POJ 1704 Georgia and Bob【博弈】
来源:互联网 发布:成立淘宝客团队 编辑:程序博客网 时间:2024/05/16 18:05
题目链接:
http://poj.org/problem?id=1704
题意:
给定棋子及其在格子上的坐标,两个人轮流选择一个棋子向左移动,每次至少移动一格,但是不可以碰到其他棋子。无路可走的时候视为输。问最后谁赢。
分析:
将棋牌上的棋子两两看成一组,将他们之间的空格看成棋子,这样就可以转化为Nim游戏
右边的棋子向左走相当于从堆中拿走石子,左边的棋子向左走,增加了棋子的数量,但是只要对手将所加的部分减回去又回到了原来的状态,同样可以转化为Nim问题。
代码:
#include<iostream>#include<algorithm>#include<cstring>using namespace std;const int maxn = 1005;int p[maxn];int main (void){ int T;cin>>T; while(T--){ int N;cin>>N; int x = 0; for(int i = 0; i < N; i++) cin>>p[i]; if(N & 1) p[N++] = 0; sort(p, p + N); for(int i = 0; i + 1 < N; i += 2){ x ^= (p[i + 1] - p[i] - 1); } if(x) cout<<"Georgia will win"<<endl; else cout<<"Bob will win"<<endl; } return 0;}
0 0
- poj 1704 Georgia and Bob(博弈)
- POJ 1704(Georgia and Bob-Nim博弈)
- poj 1704 Georgia and Bob 博弈
- POJ 1704 Georgia and Bob(博弈)
- poj 1704 Georgia and Bob 阶梯博弈
- poj 1704Georgia and Bob nim博弈
- POJ 1704:Georgia and Bob 阶梯博弈
- POJ 1704 Georgia and Bob【博弈】
- POJ 1704 Georgia and Bob 博弈
- POJ 1704 Georgia and Bob(博弈)
- POJ 1704 Georgia and Bob(阶梯博弈)
- [阶梯博弈] POJ 1704 Georgia and Bob
- POJ 1704 Georgia and Bob (Nim博弈)
- POJ-1704 Georgia and Bob (阶梯博弈)
- POJ 1704 Georgia and Bob (博弈:Staircase Nim)
- poj 1704 Georgia and Bob(阶梯博弈)
- [POJ 1704] Georgia and Bob (尼姆博弈变形)
- POJ-1704 Georgia and Bob (阶梯博弈)
- 单例模式+synchronized的学习
- BZOJ 4012 HNOI 2015 开店(shop) 一道简单的点剖题
- 删除恶意资料
- 谈谈SVPullToRefresh
- hadoop命令详解
- POJ 1704 Georgia and Bob【博弈】
- CSS:box-sizing的使用
- SpriteKit与SceneKit
- Hbase shell详情
- 打印1到最大的n位数
- PHP字符串函数之 strstr stristr strchr strrchr
- Android_SlidingMenu开源项目_导航框架实现侧滑
- poj 备忘录
- ACM ProblemB