A Simple Nim (SG Table Finding Law)

Two players take turns picking candies from n heaps, the player who picks the last one will win the game.On each turn they can pick any number of candies which come from the same heap( picking no candy is not allowed).To make the game more interesting, players can separate one heap into three smaller heaps(no empty heaps) instead of the picking operation.Please find out which player will win the game if each of them never make mistakes.
 
Input
Intput contains multiple test cases. The first line is an integer 1T100< /span>, the number of test cases. Each case begins with an integer n, indicating the number of the heaps, the next line contains N integers s[0],s[1],....,s[n1] span> , representing heaps with s[0],s[1],...,s[n1] objects respectively. (1n106,1s[i]109) span> span>
 

< /p>

Output
For each test case,output a line whick contains either”First player wins.”or”Second player wins”.
 
Sample Input
2 2 4 4 3 1 2 4

 

 
Sample Output
Second player wins. First player wins.

 

 
Author
UESTC
 
Source
2016 Multi-University Training Contest 6

 

 

 

Recommend
wange2014 We have carefully selected several similar problems for you: 6742 6741 6740 6739 6738
 
 
#include

#include

#include

#include
<string.h>
#include

using namespace std;
typedef
long long ll;


//void getsg(int x){
// memset(vis,0,sizeof(vis));
// for(int i=0;i<x;i++ ){="" <br=""></x;i++>// vis[sg[i]]=1;
//}
// for(int i1=1;i1<x;i1++ ){="" <br=""></x;i1++>// for(int i2=1;i2<x;i2++ ){="" <br=""></x;i2++>// for(int i3=1;i3<x;i3++ ){="" <br=""></x;i3++>// if(i1+i2+i3==x) vis [sg[i1]^sg[i2]^sg[i3]]=1;
//}
//}
//}
// for(int i=0;;i++){
// if(vis[i]==0){
// sg[x]=i;
// break;
//}
//}
//}


int main(){
// for(int i=1;i<=50; i++){
// getsg(i);
// printf("i:%d %d %d\ n",i,sg[i],sg[i]==i);
// }
int t;
scanf(
"%d",&t);
while(t--){
int n;
scanf(
"%d",&n);
int ans=0;
int tem;
for(int i=1;i<=n;i++){
scanf(
"%d",&tem);
if(tem%8==0) tem--;
else if(tem%8==7) tem++;
ans
=ans^tem;
}
if(ans==0) printf(< span style="color: #800000;">"Second player wins.\n ");
else printf("First player wins.\n");
}
}

 

 

 

Two players take turns picking candies from n heaps, the player who picks the last one will win the game. On each turn they can pick any number of candies which come from the same heap(picking no candy is not allowed).To make the game more interesting, players can separate one heap into three smaller heaps(no empty heaps) instead of the picking operation.Please find out which player will win the game if each of them never make mistakes.

 

Input

Intput contains multiple test cases. The first line is an integer 1T< span style=”display: inline-block; overflow: hidden; height: 1px; width: 0.12em;”>100< /span>, the number of test cases. Each case begins with an integer n, indicating the number of the heaps, the next line contains N integers < span id=”MathJax-Span-9″ class=”mrow”>s [0],s[1],....,s[n1]< /span>, representing heaps with s[0],s[1],..., s[n1]< /span> objects respectively.( 1n106,1s[i]109) span>

 

Output

For each test case,output a line whick contains either”First player wins.”or”Second player wins”.

 

Sample Input

 

2 2 4 4 3 1 2 4

 

2 2 4 4 3 1 2 4

 

Sample Output

 

Second player wins. First player wins.

 

Second player wins. First player wins.< /p>

Author

UESTC

 

Source

2016 Multi-University Training Contest 6

 

Recommend

wange2014 We have carefully selected several similar problems for you: 6742 6741 6740 6739 6738

 

#include

#include

#include

#include
<string.h>
#include

using namespace std;
typedef
long long ll;


//void getsg(int x){
// memset(vis,0,sizeof(vis));
// for(int i=0;i<x;i++ ){="" <br=""></x;i++>// vis[sg[i]]=1;
//}
// for(int i1=1;i1<x;i1++ ){="" <br=""></x;i1++>// for(int i2=1;i2<x;i2++ ){="" <br=""></x;i2++>// for(int i3=1;i3<x;i3++ ){="" <br=""></x;i3++>// if(i1+i2+i3==x) vis [sg[i1]^sg[i2]^sg[i3]]=1;
//}
//}
//}
// for(int i=0;;i++){
// if(vis[i]==0){
// sg[x]=i;
// break;
//}
//}
//}


int main(){
// for(int i=1;i<=50; i++){
// getsg(i);
// printf("i:%d %d %d\ n",i,sg[i],sg[i]==i);
// }
int t;
scanf(
"%d",&t);
while(t--){
int n;
scanf(
"%d",&n);
int ans=0;
int tem;
for(int i=1;i<=n;i++){
scanf(
"%d",&tem);
if(tem%8==0) tem--;
else if(tem%8==7) tem++;
ans
=ans^tem;
}
if(ans==0) printf("Second player wins.\n");
else printf("First player wins.\n");
}
}

 

 

 

#include

#include

#include

#include
<string.h>
#include

using namespace std;
typedef
long long ll;


//void getsg(int x){
// memset(vis,0,sizeof(vis));
// for(int i=0;i<x;i++){ <br=""></x;i++){>// vis[sg[i]]=1;
// }
// for(int i1=1;i1<x;i1++){ <br=""></x;i1++){>// for(int i2=1;i2<x;i2++){ <br=""></x;i2++){>// for(int i3=1;i3<x;i3++){ <br=""></x;i3++){>// if(i1+i2+i3==x) vis[sg[i1]^sg[i2]^sg[i3]]=1;
// }
// }
// }
// for(int i=0;;i++){
// if(vis[i]==0){
// sg[x]=i;
// break;
// }
// }
//}


int main(){
// for(int i=1;i<=50;i++){
// getsg(i);
// printf("i:%d %d %d\n",i,sg[i],sg[i]==i);
// }
int t;
scanf(
"%d",&t);
while(t--){
int n;
scanf(
"%d",&n);
int ans=0;
int tem;
for(int i=1;i<=n;i++){
scanf(
"%d",&tem);
if(tem%8==0) tem--;
else if(tem%8==7) tem++;
ans
=ans^tem;
}
if(ans==0) printf("Second player wins.\n");
else printf("First player wins.\n");
}
}

 

Leave a Comment

Your email address will not be published.