其他分享
首页 > 其他分享> > K Dress as women

K Dress as 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