標籤:style color os io for ar 2014 art
思路介紹:
1. 如果首先由Alice取,定義ans[i],如果ans[i]=1表示Alice會取勝,反之Bob取勝。枚舉前100項,ans[1]=0,ans[2]=1,ans[i]=!(ans[i-1]&&ans[i-2]);
可以發現規律:當i為2,3,5,6,8,9....時Alice取勝,所以Alice取勝的條件為:i%3!=1;
2.如果Bob先取,ans[1]=1,ans[2]=1,ans[i]=!(ans[i-1]&&ans[i-2])
規律:當i為1,2,4,5,7,8...時Bob取勝,、;所以Bob取勝的條件為:i%3!=0;
1020 - A Childhood Game
PDF (English) Statistics Forum
Time Limit: 0.5 second(s) Memory Limit: 32 MB
Alice and Bob are playing a game with marbles; you may have played this game in childhood. The game is playing by alternating turns. In each turn a player can take exactly one or two marbles.
Both Alice and Bob know the number of marbles initially. Now the game can be started by any one. But the winning condition depends on the player who starts it. If Alice starts first, then the player who takes the last marble looses the game. If Bob starts first, then the player who takes the last marble wins the game.
Now you are given the initial number of marbles and the name of the player who starts first. Then you have to find the winner of the game if both of them play optimally.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains an integer n (1 ≤ n < 231) and the name of the player who starts first.
Output
For each case, print the case number and the name of the winning player.
Sample Input
Output for Sample Input
3
1 Alice
2 Alice
3 Bob
Case 1: Bob
Case 2: Alice
Case 3: Alice
PROBLEM SETTER: JANE ALAM JAN
<span style="color:#6600cc;">/************************************** author : Grant Yuan time : 2014/8/20 13:38 algorithm: 博弈 source : LightOj 1020***************************************/#include<bits/stdc++.h>#define Alice "Alice"#define Bob "Bob"using namespace std;char s[6];int n,t;int main(){ scanf("%d",&t); for(int i=1;i<=t;i++) { memset(s,0,sizeof(s)); scanf("%d%s",&n,s); printf("Case %d: ",i); if(strcmp(s,Alice)==0){ if(n%3==1){ printf("Bob\n"); } else{ printf("Alice\n"); } } else{ if(n%3==0){ printf("Alice\n"); } else{ printf("Bob\n"); } } } /*ans[1]=false;ans[2]=true; for(int i=3;i<=100;i++) { ans[i]=true; if(ans[i-1]&&ans[i-2]) ans[i]=false; } for(int i=1;i<=100;i++) { printf("%d ",i); if(ans[i]) printf("1\n"); else printf("0\n"); }*/ return 0;}</span>