Nim or not Nim
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 792 Accepted Submission(s): 371
Problem Description Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap.
Nim is usually played as a misere game, in which the player to take the last object loses. Nim can also be played as a normal play game, which means that the person who makes the last move (i.e., who takes the last object) wins. This is called normal play because most games follow this convention, even though Nim usually does not.
Alice and Bob is tired of playing Nim under the standard rule, so they make a difference by also allowing the player to separate one of the heaps into two smaller ones. That is, each turn the player may either remove any number of objects from a heap or separate a heap into two smaller ones, and the one who takes the last object wins.
Output For each test case, output a line which contains either "Alice" or "Bob", which is the winner of this game. Alice will play first. You may asume they never make mistakes.
Sample Input
2 3 2 2 3 2 3 3
Sample Output
Alice Bob
Source 2009 Multi-University Training Contest 13 - Host by HIT
给你n堆石子,你每次可以从每一堆中取任意石子或者将此堆石子分成两份,谁最后取得谁获胜。 求SG函数,打表发现规律:sg[4k+1]=4k+1,sg[4k+2]=4k+2,sg[4k+3]=4k+4,sg[4k+4]=4k+3. SG打表函数:
#include#include int sg[1007],vis[1007]; int main() { sg[0]=0;sg[1]=1; int j; for(int i=2;i<=100;i++) { memset(vis,0,sizeof(vis)); for(j=1;j
//0MS 228K #includeint main() { int t; while(scanf("%d",&t)!=EOF) { while(t--) { int n,a,mod,sum=0; scanf("%d",&n); for(int i=1; i<=n; i++) { scanf("%d",&a); mod=a%4; if(mod==3)sum^=(a+1); else if(mod==0)sum^=(a-1); else sum^=a; } if(sum)printf("Alice\n"); else printf("Bob\n"); } } }