ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

K Dress as women

2020-06-17 12:07:27  阅读:337  来源: 互联网

标签:cnt ch 20 int ans include Dress women


https://ac.nowcoder.com/acm/contest/5944/K

One day, zyh and fzj are playing a game called Bejeweled, and they have promised the loser would dress as women.

The rules are as follows, in a two-dimensional plane, each time one can remove one or multiple collinear points from the plane. The one who removes the last point on the plane will win the game.

They both want the other to dress as women, so they always make the best choice. Now fyt wants to know who will lose. Note that zyh will always take the first.

题目大意:二维平面上面有一堆点,然后两个人轮流消除一些点,要么消除一个点,要么消除共线的点

数据很小,将n状压一下,然后爆搜当前状态,如果sg[(1 << n) - 1] == 1 , 那么先手就赢了,必胜态,否则就输了。

对于当前状态ans而言,

  1. 如果存在某一个状态res是ans的子状态 , 并且这个子状态是必输状态
  2. 而且呢,res^ans表示两者的差集,也就是当前操作者要消除的点集,
    如果这些点集在一条直线上面
    满足这两个条件,当前操作者绝对是必胜状态
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#include <set>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std ;
#define ios ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define x first
#define y second
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
ll in()
{
  ll x = 0 , f = 1 ;
  char ch = getchar() ;
  while(!isdigit(ch)) {if(ch == '-') f = -1 ; ch = getchar() ;}
  while(isdigit(ch)) x = x * 10 + ch - 48 , ch = getchar() ;
  return x * f ;
}
int n , x[20] , y[20] , sg[N] , X[20] , Y[20];
bool check(int ans)
{
  int cnt = 0 ;
  for(int i = 0 ;i < n ;i ++ ) if((ans >> i) & 1) X[++ cnt] = x[i] , Y[cnt] = y[i] ;
  if(cnt <= 2) return 1 ;
  for(int i = 3; i <= cnt ;i ++ )
   if(1ll * (X[i] - X[1]) * (Y[2] - Y[1]) != 1ll * (X[2] - X[1]) * (Y[i] - Y[1]))
     return 0 ;
  return 1;
}
bool dfs(int ans)
{
  if(sg[ans] != -1) return sg[ans] ;
  if(check(ans)) return sg[ans] = 1;
  for(int i = (ans - 1) & ans ;i ; i = (i - 1) & ans)
   if(check(ans ^ i) && !dfs(i))
    return sg[ans] = 1 ;
  return sg[ans] = 0 ;
}
int main()
{
  n = in() ;
  for(int i = 0; i < n ;i ++ ) x[i] = in() , y[i] = in() ;
  memset(sg , -1 , sizeof sg) ;
  sg[0] = 0 ;
  if(dfs((1 << n) - 1)) puts("zyh") ;
  else puts("fzj") ;
  return 0 ;
}
/*
*/


标签:cnt,ch,20,int,ans,include,Dress,women
来源: https://www.cnblogs.com/spnooyseed/p/13151678.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有