POJ 1704 Georgia and Bob(nim博弈论)
来源:互联网 发布:c语言输出心形图案 编辑:程序博客网 时间:2024/05/16 17:04
题目地址:POJ 1704
这个题实在巧妙。。居然这样就可以转化成了经典的nim模型。
这题可以从左往右两两配对,如果是奇数个的话,就让最左边的与0配对。然后每当对方移动某一对的前一个,你总可以移动该对的后一个来移动回来。所以这是没有影响的。有影响的只是每一对中间的空格数。这就转化成了((n+1)/2)堆石子的游戏,每一堆的石子个数是每一对点之间的空格数。然后用异或求解。
代码如下:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int a[2000];int main(){ int t, n, i, s, j, sum; scanf("%d",&t); while(t--) { scanf("%d",&n); a[0]=0; for(i=1;i<=n;i++) { scanf("%d",&a[i]); } sort(a+1,a+n+1); if(n&1) { s=0; } else s=1; sum=0; for(i=s;i<=n;i+=2) { sum^=a[i+1]-a[i]-1; } if(!sum) puts("Bob will win"); else puts("Georgia will win"); } return 0;}
0 0
- POJ 1704 Georgia and Bob(nim博弈论)
- POJ 1704(Georgia and Bob-Nim博弈)
- poj 1704Georgia and Bob nim博弈
- POJ 1704 Georgia and Bob <Nim变形>
- POJ 1704 Georgia and Bob (Nim博弈)
- POJ 1704 Georgia and Bob (博弈:Staircase Nim)
- POJ 1704 Georgia and Bob (Nim游戏变形)
- POJ 1704 Georgia and Bob(nim变型)
- POJ 1704-Georgia and Bob棋子移动(Nim博弈)
- POJ 1704 Georgia and Bob (博弈 Nim游戏变形)
- POJ 1704 Georgia and Bob (Nim博弈)
- POJ Georgia 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
- SSH面试题整理
- Remove Nth Node From End of List
- VIJOS P1908合唱队形
- leetcode面试题3:Max Points on a Line
- 集群中几种session同步解决方案的比较
- POJ 1704 Georgia and Bob(nim博弈论)
- 科学计算器(可实现带括号的浮点数四则运算)
- VIJOS P1777引水入城
- xmemcached的缓存更新机制
- zoj 2822 - Sum of Different Primes
- 基于套接字的编程
- 请假模块工作流分析(2)
- Nginx的介绍和使用
- 我的编程之路点滴记录(四)