Light OJ 1253 Misere Nim (尼姆博弈(2))

LightOJ1253 :Misere Nim

时间限制:1000MS    内存限制:32768KByte   64位IO格式:%lld & %llu
描述

Alice and Bob are playing game of Misère Nim. Misère Nim is a game playing on k piles of stones, each pile containing one or more stones. The players alternate turns and in each turn a player can select one of the piles and can remove as many stones from that pile unless the pile is empty. In each turn a player must remove at least one stone from any pile. Alice starts first. The player who removes the last stone loses the game.

输入

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case starts with a line containing an integer k (1 ≤ k ≤ 100). The next line contains k space separated integers denoting the number of stones in each pile. The number of stones in a pile lies in the range [1, 109].

输出

For each case, print the case number and 'Alice' if Alice wins otherwise print 'Bob'.

样例输入

3

4

2 3 4 5

5

1 1 2 4 10

1

1

样例输出

Case 1: Bob

Case 2: Alice

Case 3: Bob

题目来源
Problem Setter: Jane Alam Jan 
 
题意
k堆石子,每堆个数不定,每次取一堆中的任意个,谁取到最后一个谁输。
题解
详见上篇博客 尼姆博弈 s1,s2,t0为必胜态。
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int i,n,t,k,data,ans,chongyu,cas=;
cin>>t;
while(t--)
{
cin>>k;
chongyu=ans=;
for(i=;i<k;i++)
{
cin>>data;
if(data>)
chongyu++;
ans^=data;
}
if((ans&&chongyu)||(!ans&&!chongyu)) //s1,s2,t0
printf("Case %d: Alice\n",cas++);
else
printf("Case %d: Bob\n",cas++);
}
return ;
}
 
上一篇:生产环境中学习Redis


下一篇:iphone开发中数据持久化之——嵌入式SQLite(三)