ZOJ 3964 Yet Another Game of Stones (博弈)
2017-05-03 15:18
363 查看
题意:题意跟普通的nim博弈差不多 就是一位选手取的时候 加了一个限制条件
思路:
1.全部b[i]=0 那么 这个就是Al先手的NIM博弈
2.有多个b[i]>=1&&a[i]>1的情况 ,BO肯定会破环这几堆 让 AL不能取这堆 那么AL肯定会输。
接下来就是b[i]=1 同时a[i]=1时这个跟普通也一样,
当a[i]>1的个数为1 时,
b[i]=1,a[i]>1时 就要分情况了 如果a[i]为奇数,AL可以一下取完 剩下的就变成了BO先手的博弈 当a[i]为偶数时,AL只能让这一堆的个数为1,这样才能保证BO不能碰坏这一堆 让 AL不能取。这样 也变成BO先手的博弈。
b[i]=2,a[i]>1时 当a[i] 为奇数 AL怎么也取不完 所以AL肯定会输,当a[i]为偶数时,Al可以一下取完这一堆 那么 剩下就是BO先手的博弈。
代码:
思路:
1.全部b[i]=0 那么 这个就是Al先手的NIM博弈
2.有多个b[i]>=1&&a[i]>1的情况 ,BO肯定会破环这几堆 让 AL不能取这堆 那么AL肯定会输。
接下来就是b[i]=1 同时a[i]=1时这个跟普通也一样,
当a[i]>1的个数为1 时,
b[i]=1,a[i]>1时 就要分情况了 如果a[i]为奇数,AL可以一下取完 剩下的就变成了BO先手的博弈 当a[i]为偶数时,AL只能让这一堆的个数为1,这样才能保证BO不能碰坏这一堆 让 AL不能取。这样 也变成BO先手的博弈。
b[i]=2,a[i]>1时 当a[i] 为奇数 AL怎么也取不完 所以AL肯定会输,当a[i]为偶数时,Al可以一下取完这一堆 那么 剩下就是BO先手的博弈。
代码:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int n; const int maxn=1e5+100; int a[maxn],b[maxn]; int main(int argc, const char * argv[]) { int t; cin>>t; while (t--) { scanf("%d",&n); for (int i=0; i<n; ++i) { scanf("%d",&a[i]); } int cnt[3]={0}; int num[3]; for (int i=0; i<n; ++i) { scanf("%d",&b[i]); ++cnt[b[i]]; if((b[i]==1&&a[i]==1)){ --cnt[b[i]]; ++cnt[0]; b[i]=0; } if(cnt[b[i]]==1) num[b[i]]=a[i]; } if (cnt[0]==n) { int ans=0; for (int i=0; i<n; ++i) ans^=a[i]; if (ans) puts("Alice"); else puts("Bob"); } else if((cnt[2]==0&&cnt[1]==1)||(cnt[1]==0&&cnt[2]==1&&!(num[2]&1))){ int ans=0; for (int i=0; i<n; ++i) { if (!b[i]) ans^=a[i]; } if (cnt[1]==1&&!(num[1]&1)) ans^=1; if (ans) puts("Bob"); else puts("Alice"); } else puts("Bob"); } return 0; }
相关文章推荐
- ZOJ 3964 Yet Another Game of Stones(Nim博弈 待整理)
- Yet Another Game of Stones ZOJ - 3964 (博弈)
- ZOJ 3964 Yet Another Game of Stones (博弈)
- ZOJ 3964 Yet Another Game of Stones(博弈论)
- Yet Another Game 4000 of Stones---ZOJ Problem 3964
- Yet Another Game of Stones
- 2017浙江省赛:Yet Another Game of Stones(尼姆变形)
- Codeforces Round #399 E Game of Stones 博弈
- Codeforces Round #399 E Game of Stones 博弈
- Codeforces Round #399 E Game of Stones 博弈
- codeforces 768 E Game of Stones(博弈)
- Game of Taking Stones (大数 + 威佐夫博弈 java写的)
- Codeforces Round #399 E Game of Stones 博弈
- Codeforces Round #399 E Game of Stones 博弈
- codeforces 399 E. Game of Stones 博弈 思维题
- Codeforces Round #399 E Game of Stones 博弈
- Codeforces Round #399 (Div. 1 + Div. 2, combined) (博弈,Nim游戏)E.Game of Stones
- zoj 3610 Yet Another Story of Rock-paper-scissors 忽悠。。
- ZOJ 3505 Yet Another Set of Numbers
- 2016 ICPC 大连 C Game of Taking Stones 【威佐夫博弈+大数+高精度】