其次因為上述實現,每次集合中加入的是一個點對 ( 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;
}