HDU 1907&&2509
N堆取石子,取完最后者输。
有个叫SJ定理。
#include"iostream" using namespace std; int main() { int t; cin>>t; while(t--) { int s[50],n; cin>>n; int i,flag=0,ans=0; for(i=0;i<n;i++) { cin>>s[i]; ans^=s[i]; if(s[i]>1) flag=1; } if(!flag) { if(n%2==0) cout<<"John"<<endl; else cout<<"Brother"<<endl; continue; } if(ans){ cout<<"John"<<endl; continue; } cout<<"Brother"<<endl; } return 0; }
2509
#include"iostream" using namespace std; int main() { int t; while(cin>>t) { int s; int i,flag=0,ans=0; for(i=0;i<t;i++) { cin>>s; ans^=s; if(s>1) flag=1; } if(!flag) { if(t%2==0) cout<<"Yes"<<endl; else cout<<"No"<<endl; continue; } if(ans){ cout<<"Yes"<<endl; continue; } cout<<"No"<<endl; } return 0; }