其次因为上述实现,每次集合中加入的是一个点对 ( x , y ) ,所以每个集合中至少有两个元素,基于此,如果现在起点在点 p ,如果点 p 属于集合 s 中,则可以先手选择 s 中的除了点 p 外的任意一个点(因为每个集合中的点对距离都是相同的),此时后手只能跨集合选择,先手依然选择新的集合中的另外一个点,如此往复,先手必胜
如果点 p 不属于任何一个集合的话,那么先手无论选择哪个点,肯定都会对应着一个集合,后手只需要按照必胜策略选择就好了,这样先手就必败
用了两个数组模拟集合和标记的运算
代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
#include<unordered_map>
using namespace std;typedef long long LL;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const int N=2e3+100;struct Edge
{int x,y;LL dis;bool operator<(const Edge& t)const{return dis>t.dis;}
}edge[N*N];struct Point
{LL x,y;void input(){scanf("%lld%lld",&x,&y);}LL dis(Point& t){return (t.x-x)*(t.x-x)+(t.y-y)*(t.y-y);}
}point[N];bool sg[N],vis[N];int main()
{
#ifndef ONLINE_JUDGE
// freopen("data.in.txt","r",stdin);
// freopen("data.out.txt","w",stdout);
#endif
// ios::sync_with_stdio(false);int w;cin>>w;while(w--){int n,cnt=0;scanf("%d",&n);memset(vis,false,n+5);memset(sg,false,n+5);for(int i=1;i<=n;i++)point[i].input();for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)edge[++cnt].x=i,edge[cnt].y=j,edge[cnt].dis=point[i].dis(point[j]);sort(edge+1,edge+1+cnt);int r=1;while(r<=cnt){int l=r;while(edge[r].dis==edge[l].dis)r++;for(int i=l;i<r;i++)//[l,r)这段点对的距离都是相等的{int x=edge[i].x,y=edge[i].y;if(!vis[x]&&!vis[y])sg[x]=sg[y]=true;}for(int i=l;i<r;i++){int x=edge[i].x,y=edge[i].y;vis[x]|=sg[x],vis[y]|=sg[y];}}if(sg[1])puts("YES");elseputs("NO");}return 0;
}