Nim or not Nim? hdu3032 SG值打表找规律

Nim or not Nim?


Time Limit: 2000/1000 MS
(Java/Others)    Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 858    Accepted
Submission(s): 412

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

 1 #include<stdio.h>
2 #include<string.h>
3 #include<map>
4 #include<math.h>
5 #include<iostream>
6 #include<algorithm>
7 using namespace std;
8
9 int main()
10 {
11 int t,i,n,ans,j,x;
12 scanf("%d",&t);
13 for(i=1;i<=t;i++)
14 {
15 ans=0;
16 scanf("%d",&n);
17 for(j=0;j<n;j++)
18 {
19 scanf("%d",&x);
20 if(x%4==0)x--;
21 else if(x%4==3)x++;
22 ans^=x;
23 }
24 if(ans)
25 printf("Alice\n");
26 else printf("Bob\n");
27 }
28 }

Sample Output

Alice

Bob

Nim or not Nim? hdu3032 SG值打表找规律

时间: 2024-10-11 06:14:35

Nim or not Nim? hdu3032 SG值打表找规律的相关文章

[hdu-5795]A Simple Nim 博弈 尼姆博弈 SG函数打表找规律

[题目]题目链接 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 int

hdu_5795_A Simple Nim(打表找规律的博弈)

题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时sg[x]=8k+8, 当x=8k+8时sg[x]=8k+7, 其余时候sg[x]=x:(k>=0) 1 #include<cstdio> 2 3 int main() 4 { 5 int t,n,ans,tp; 6 scanf("%d",&t); 7 while

【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones

打表找规律即可. 1,1,2,2,2,3,3,3,3,4,4,4,4,4... 注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关. //#include<cstdio> //#include<set> //#include<cstring> //using namespace std; //bool vis[16]; //int n,SG[16][1<<16]; //int sg(int x,int moved) //{ // if(SG

hdu 2147 kiki&#39;s game(DP(SG)打表找规律)

题意: n*m的棋盘,一枚硬币右上角,每人每次可将硬币移向三个方向之一(一格单位):左边,下边,左下边. 无法移动硬币的人负. 给出n和m,问,先手胜还是后手胜. 数据范围: n, m (0<n,m<=2000) 思路: dp[i][j]=0,说明从(i,j)这个点到时左下角先手败.dp[i][j]=1则先手胜. 然后记忆搜.但是记忆搜会超时. 搜完把整张表打出来,发现规律了,,,,然后,,,代码剩几行了. 代码: ///打表观察 /* int f[2005][2005]; int go(in

HDU 3032 (SG打表找规律)

题意: 有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范围比较大,所以最好通过SG打表的结果找出规律在解. sg(4k+1)=4k+1;sg(4k+2)=4k+2;sg(4k+3)=4k+4; sg(4k)=4k-1; 1 2 4 3 5 6 8 7 Sample Input232 2 323 3 Sample OutputAliceBob SG打表找规律

HDU 3032 Nim or not Nim?(博弈 SG打表找规律)

传送门 Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1457    Accepted Submission(s): 720 Problem Description Nim is a two-player mathematic game of strategy in which players take

石油大训练 Little Sub and Johann (博弈SG打表找规律)

Little Sub and Johann 题目描述 Little Sub and Johann are good friends and they often play games together. Recently, they like playing with stones.They have n piles of stones initially and they should make one of following movements by turns:1.Erase a pil

hdu 3032 sg打表找规律 *

有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 打表代码: 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cstdlib> 5 using namespace std; 6 const int N=1000010; 7 int sg[N];

【NOIP 模拟赛】中值滤波 打表找规律

对于这样看起来不像什么算法也没什么知识点的题,一脸懵逼的话不是手推规律就是打表找规律......... 当然还有一些超出你能力之外的数学题...... #include <cstdio> const int N=500010; int n,ans,A[N]; inline int Max(int x,int y){ return x>y?x:y; } int main(){ scanf("%d",&n); int last,now,P=0; for(int i