标签:str cond sea ott title preview queue tin more
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
题意:跟普通的nim不一样的是,一堆可以分成三小堆;
思路:sg函数打表找规律;
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<set> #include<map> #include<queue> #include<stack> #include<vector> using namespace std; typedef long long ll; #define PI acos(-1.0) const int N=1e3+100,maxm=1e5+100,inf=0x3f3f3f3f,mod=1e9+7; const ll INF=1e18+7; int sg[N],mex[N]; void initsg() { for(int i=1;i<=500;i++) { memset(mex,0,sizeof(mex)); for(int j=1;j<=i-2;j++) { for(int k=1;k+j<i;k++) { int l=i-j-k; mex[sg[l]^sg[j]^sg[k]]=1; } } for(int j=1;j<=i;j++) mex[sg[j]]=1; for(int j=1;;j++) if(!mex[j]) { sg[i]=j; break; } } for(int i=1;i<=500;i++) if(sg[i]!=i)cout<<sg[i]<<" "<<i<<endl; } int SG(int x) { if(x%8==7)return x+1; if(x%8==0)return x-1; return x; } int main() { //initsg(); int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); int ans=0; for(int i=1;i<=n;i++) { int x; scanf("%d",&x); ans^=SG(x); } if(ans)printf("First player wins.\n"); else printf("Second player wins.\n"); } return 0; }
标签:str cond sea ott title preview queue tin more
原文地址:http://www.cnblogs.com/jhz033/p/7399844.html