POJ 2234 Matches Game (经典Nim博弈)
2016-07-31 23:24
295 查看
题目连接
题意:
给你M堆物品,让两个人进行轮流选择,每一个人可以选择任意一堆的任意个物品,假设每个人都很聪明,求解这种情况下是前者必赢还是后者必赢,
直接Nim博弈,判断sum = A[0] ^ A[1] ^ A[2] ...即可
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 20 + 5;
const int MAXM = 1e3 + 5;
int A[MAXN], n;
int main(){
while(~scanf("%d", &n)){
int sum = 0;
for(int i = 0;i < n;i ++){
scanf("%d", &A[i]);
sum ^= A[i];
}
if(sum){
printf("Yes\n");
}
else{
printf("No\n");
}
}
return 0;
}
题意:
给你M堆物品,让两个人进行轮流选择,每一个人可以选择任意一堆的任意个物品,假设每个人都很聪明,求解这种情况下是前者必赢还是后者必赢,
直接Nim博弈,判断sum = A[0] ^ A[1] ^ A[2] ...即可
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 20 + 5;
const int MAXM = 1e3 + 5;
int A[MAXN], n;
int main(){
while(~scanf("%d", &n)){
int sum = 0;
for(int i = 0;i < n;i ++){
scanf("%d", &A[i]);
sum ^= A[i];
}
if(sum){
printf("Yes\n");
}
else{
printf("No\n");
}
}
return 0;
}
相关文章推荐
- POJ 2234 Matches Game(Nim博弈裸题)
- 【 数论 Nim博弈 】POJ 2234 Matches Game
- POJ 2234 Matches Game (nim博弈裸题)
- POJ - 2234 Matches Game【Nim博弈】
- poj 2234 博弈-Nim
- poj 2234基础Nim博弈||sg博弈
- POJ 2234 Matches Game(取火柴博弈1)
- [博弈]POJ 2234 Matches Game
- poj 2234 Matches Game (博弈)
- POJ 2234 Matches Game(博弈)
- POJ 2234-Matches Game(博弈)
- poj 2234基础Nim博弈||sg博弈
- POJ 2234 Matches Game(直接的NIM)
- POJ 2234 Matches Game 博弈论水题 Nim模型
- [POJ](2975)Nim ---Nim博弈(博弈)
- POJ 1704 Georgia and Bob(阶梯Nim博弈)
- pku 2234 matches game 博弈
- POJ - 1704 Georgia and Bob (Nim博弈的变形)
- poj 2234 博弈论Nim取子游戏
- poj 2975 Nim 尼姆博弈