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就先手必败(仅需记住这句就够应付此类题了),否则先手胜。
AC代码
思路:
设 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代码
相关文章推荐
- hiho一下 第四十五周 博弈游戏·Nim游戏·二(转成NIm)
- hiho一下 第四十四周 博弈游戏
- hihoCoder hiho一下 第四十六周 博弈游戏·Nim游戏·三( sg函数 )
- hihocoder 1163 博弈游戏·Nim游戏
- hiho一下 第四十四周 题目1 : 博弈游戏·Nim游戏
- 6.游戏特别离不开脚本(3)-JS脚本操作java(2)(直接解析JS公式,并非完整JS文件或者函数)
- hiho 1163 博弈游戏·Nim游戏
- 6.游戏特别离不开脚本(3)-JS脚本操作java(直接解析JS公式,并非完整JS文件或者函数)
- 【HIHOCODER 1163】 博弈游戏·Nim游戏
- hiho一下 第四十五周 博弈游戏·Nim游戏·二 [ 博弈 ]
- hihoCoder hiho一下 第四十四周 博弈游戏·Nim游戏
- 洛谷.2197.nim游戏(博弈论 Nim)
- cocos2dx 直接修改 Texture 里面的数据 mark一下 updateWithData
- hiho一下第一周——最长回文子串
- adt直接用,集成svn,里边有sources直接关联一下就可以用
- 编程之美 - NIM“拈”游戏分析
- 编程之美——NIM(1)一排石头的游戏
- Steam游戏黑屏与游戏直接安装方法
- 闲聊一下android 3D 网络游戏
- 探秘腾讯Android手机游戏平台之不安装游戏APK直接启动法