poj 1704 Georgia and Bob阶梯博弈
2016-11-20 11:29
429 查看
点击打开链接
把棋子两两组成一对,其距离看作nim中石子的数量
右边的棋子向左移动 距离减小 相当于在该堆中拿石子
左边的棋子向左移动 距离增加 石子增多,但是下一步可以移动其右边的棋子,使之恢复至原来的状态
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int N=1e5+20;
int p
,a
;
//nim石子全为0,必败态即异或为0
//异或为0必定转化到异或非0(异或消去律)
//异或非0&&=k 则将a[i]修改为a[i]^k,即可
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
p[0]=0;
for(int i=1;i<=n;i++)
{
cin>>p[i];
}
sort(p+1,p+1+n);
int num=0;
if(n%2==0)
for(int i=2;i<=n;i+=2)
{
a[++num]=p[i]-p[i-1]-1;
}
else
for(int i=1;i<=n;i+=2)
{
a[++num]=p[i]-p[i-1]-1;
}
int ans=0;
for(int i=1;i<=num;i++)
ans^=a[i];
if(ans)
puts("Georgia will win");
else
puts("Bob will win");
}
return 0;
}
把棋子两两组成一对,其距离看作nim中石子的数量
右边的棋子向左移动 距离减小 相当于在该堆中拿石子
左边的棋子向左移动 距离增加 石子增多,但是下一步可以移动其右边的棋子,使之恢复至原来的状态
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int N=1e5+20;
int p
,a
;
//nim石子全为0,必败态即异或为0
//异或为0必定转化到异或非0(异或消去律)
//异或非0&&=k 则将a[i]修改为a[i]^k,即可
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
p[0]=0;
for(int i=1;i<=n;i++)
{
cin>>p[i];
}
sort(p+1,p+1+n);
int num=0;
if(n%2==0)
for(int i=2;i<=n;i+=2)
{
a[++num]=p[i]-p[i-1]-1;
}
else
for(int i=1;i<=n;i+=2)
{
a[++num]=p[i]-p[i-1]-1;
}
int ans=0;
for(int i=1;i<=num;i++)
ans^=a[i];
if(ans)
puts("Georgia will win");
else
puts("Bob will win");
}
return 0;
}
相关文章推荐
- 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 ( 阶梯博弈 模板 )
- POJ 1704 Georgia and Bob ( 阶梯博弈 模板 )
- POJ 1704 Georgia and Bob 博弈
- POJ 1704-Georgia and Bob(阶梯博弈)
- POJ 1704 Georgia and Bob(阶梯博弈)
- poj1704 Georgia and Bob(阶梯博弈)
- POJ 1704 Georgia and Bob(阶梯Nim博弈)
- POJ 1704 Georgia and Bob(阶梯博弈)
- poj 1704 Georgia and Bob (阶梯博弈)
- poj1704 Georgia and Bob(阶梯博弈)
- [阶梯博弈] POJ 1704 Georgia and Bob
- POJ 1704 Georgia and Bob(阶梯博弈)
- POJ 1704:Georgia and Bob 阶梯博弈
- POJ 1704 Georgia and Bob(阶梯博弈+证明)