HDU 3032 Nim or not Nim?(博弈 sg表)
2015-09-17 14:57
309 查看
Nim or not Nim?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1326 Accepted Submission(s): 656
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.
Input
Input contains multiple test cases. The first line is an integer 1 ≤ T ≤ 100, 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[N-1],
representing heaps with s[0], s[1], ..., s[N-1] objects respectively.(1 ≤ N ≤ 10^6, 1 ≤ S[i] ≤ 2^31 - 1)
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
Recommend
gaojie | We have carefully selected several similar problems for you: 3031 3033 3035 3034 3036
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<queue> #include<stack> #include<vector> #include<set> #include<map> #define L(x) (x<<1) #define R(x) (x<<1|1) #define MID(x,y) ((x+y)>>1) #define bug printf("hihi\n") #define eps 1e-8 typedef __int64 ll; using namespace std; #define INF 0x3f3f3f3f #define N 10005 int main() { int i,j,t; int n; scanf("%d",&t); while(t--) { scanf("%d",&n); int ans=0; int x; while(n--) { scanf("%d",&x); if(x%4==1) ans^=x; if(x%4==2) ans^=x; if(x%4==0) ans^=(x-1); if(x%4==3) ans^=(x+1); } if(ans) printf("Alice\n"); else printf("Bob\n"); } return 0; } /* 打sg 表看规律 sg(4k)=4k-1;sg(4k+1)=4k+1;sg(4k+2)=4k+2;sg(4k+3)=4k+4; #include<iostream> #include<string.h> #include<cstdio> #define N 1000001 using namespace std; int sg ; int g(int x) { int mex[1000]; memset(mex,0,sizeof(mex)); if(sg[x]!=-1) return sg[x]; for(int i=x-1;i>=0;i--) { mex[g(i)]=1; } for(int i=1;i<=x/2;i++) { int ans=0; ans^=g(i); ans^=g(x-i); mex[ans]=1; } for(int i=0;;i++) if(!mex[i]) return sg[x]=i; } int main() { int t , n ,x ; memset(sg,-1,sizeof(sg)); sg[0]=0; n=100; for(int i=1;i<n;i++) g(i); for(int i=0;i<=20;i++) { printf("i=%d %d\n",i,sg[i]); } return 0; } /* i=0 0 i=1 1 i=2 2 i=3 4 i=4 3 i=5 5 i=6 6 i=7 8 i=8 7 i=9 9 i=10 10 i=11 12 i=12 11 i=13 13 i=14 14 i=15 16 i=16 15 i=17 17 i=18 18 i=19 20 i=20 19 Process returned 0 (0x0) execution time : 0.194 s Press any key to continue. */
相关文章推荐
- 终于决定把自己的小窝从CSDN搬到博客园了
- ZOJ 3894 Chessgame
- Android之SurfaceView
- myeclipse从svn检出代码转成maven后格式有误解决方法
- MFC移动控件到指定位置
- 使用if IE语句判断浏览器IE版本及添加升级提示
- Gradle 构建android程序
- 关于数据库,java.lang.IllegalStateException: attempt to re-open an already-closed object
- 实现点击Item可让Item跳到屏幕中间的HorizontalScrollView
- 盒子定位
- 佛祖保佑,从来没有Bug
- 局部变量和全局变量
- 【Python之旅】第二篇(七):集合
- 【Python之旅】第二篇(七):集合
- 心得
- 【设置】PotPlayer播放完毕后停止
- php的错误和异常处理
- java.lang.UnsupportedClassVersionError: Bad version number in .class file异常的处理方法
- android 单击和滚动效果调整
- IPC框架分析 Binder,Service,Service manager