您的位置:首页 > 其它

hiho一下 第四十四周 博弈游戏·Nim游戏(直接公式解)

2015-05-03 16:43 375 查看
证明看这http://hihocoder.com/contest/hiho44/problem/1

思路:

  设 sg=a[1]^a[2]^...a
,若sg=0,则先手Alice必败,否则必赢。

  所有值的异或和为0就先手必败(仅需记住这句就够应付此类题了),否则先手胜。

#include <iostream>
using namespace std;
int stone[101], n, tmp;
int main()
{
//freopen("input.txt","r",stdin);
while(cin>>n){
scanf("%d", &tmp);
for(int i=1; i<n; i++)    scanf("%d",&stone[i]);
for(int i=1; i<n; i++)    tmp^=stone[i];
if(!tmp)    cout<<"Bob"<<endl;
else        cout<<"Alice"<<endl;
}
return 0;
}


AC代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: