开博弈论坑啦。。难度貌似没自己想象中那么大。。总之先入了门再说。。
这题其实只要判断长度为n-1或者n-2的链,bob先手的情况即可。。
然后来考虑一般链的情况。。
枚举了前几项发现先手总是必胜,那么可以得到,链上bob必胜。。
由于n<=2的时候alice可以直接取走,所以alice赢
其他情况都会成一条链,bob赢
然后来证明一下链上先手必胜。。
l=1或者l=2的时候可以直接取走。。
l>3时,直接取中点,将这段分成2个相同的链。。这样如果对手在一段上操作,我们就在另一段上进行同样操作,绝对稳赢。。
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-12
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 500005
#define nm 1000005
#define pi 3.1415926535897931
using namespace std;
const int inf=1000000007;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
int _x;
int main(){
while(_x=read())puts(_x<3?"Alice":"Bob");
return 0;
}
A Funny Game
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6588 | Accepted: 4108 |
Description
Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 10
6) coins in a circle, as Figure 1 shows. A move consists in removing one or two adjacent coins, leaving all other coins untouched. At least one coin must be removed. Players alternate moves with Alice starting. The player that removes the last coin wins. (The last player to move wins. If you can't move, you lose.)
Figure 1
Note: For n > 3, we use c1, c2, ..., cn to denote the coins clockwise and if Alice remove c2, then c1 and c3 are NOT adjacent! (Because there is an empty place between c1 and c3.)
Suppose that both Alice and Bob do their best in the game.
You are to write a program to determine who will finally win the game.
Figure 1
Note: For n > 3, we use c1, c2, ..., cn to denote the coins clockwise and if Alice remove c2, then c1 and c3 are NOT adjacent! (Because there is an empty place between c1 and c3.)
Suppose that both Alice and Bob do their best in the game.
You are to write a program to determine who will finally win the game.
Input
There are several test cases. Each test case has only one line, which contains a positive integer n (1 <= n <= 10
6). There are no blank lines between cases. A line with a single 0 terminates the input.
Output
For each test case, if Alice win the game,output "Alice", otherwise output "Bob".
Sample Input
1 2 3 0
Sample Output
Alice Alice Bob
Source
POJ Contest,Author:Mathematica@ZSU
[Submit] [Go Back] [Status] [Discuss]