【POJ1704】Georgia and Bob(博弈论)

【POJ1704】Georgia and Bob(博弈论)

题面

POJ
Vjudge

题解

这种一列格子中移动棋子的问题一般可以看做成一个阶梯博弈。
将一个棋子向左移动时,它和前面棋子的距离变小,和后面棋子的距离变大,并且减小的值和增大的值是相等的,因此,这个过程我们就可以等价成一个阶梯博弈了。

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a[1010];
int main()
{
    int T;cin>>T;
    while(T--)
    {
        int n,s=0;cin>>n;
        for(int i=1;i<=n;++i)cin>>a[i];
        sort(&a[1],&a[n+1]);
        for(int i=1;i<=n;i+=2)s^=a[n-i+1]-a[n-i]-1;
        puts(!s?"Bob will win":"Georgia will win");
    }
    return 0;
}

原文地址:https://www.cnblogs.com/cjyyb/p/9484399.html

时间: 2024-08-29 21:40:54

【POJ1704】Georgia and Bob(博弈论)的相关文章

$POJ1704\ Georgia\ and\ Bob$ 博弈论

正解:博弈论 解题报告: 传送门! 啊先放下翻译趴$QwQ$大概就是说,有一行$1\cdot n$的网格,每次可以向左移动若干步,不能越过前面已有棋子的格子就是了,然后谁不能动就输了,问最后是先手必胜还是后手必胜 然后这就是个阶梯游戏的变式昂$QwQ$ 首先可以发现,当移动一个棋子的时候,相当于和后面那个棋子的距离变大,然后和前面那个棋子的距离变小,而且总量依然是不变的 于是考虑将所有棋子按升序排列,不难发现这题就变成了一个阶梯游戏?就因为只考虑间距,那每次移动都相当于是有一个减小了然后相邻那个

[POJ1704]Georgia and Bob

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8552   Accepted: 2704 Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, number the grids from left to right by 1, 2, 3, ..., and place N ch

POJ1704 Georgia and Bob (阶梯博弈)

Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Submit Status Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, number the grids from left to right by 1, 2,

poj1704 Georgia and Bob(阶梯博弈)

Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9291   Accepted: 3021 Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, number the grids from left to right by 1, 2, 3, ...

POJ1704 Georgia and Bob 题解

阶梯博弈的变形.不知道的话还是一道挺神的题. 将所有的棋子两两绑在一起,对于奇数个棋子的情况,将其与起点看作一组.于是便可以将一组棋子的中间格子数看作一推石子.对靠右棋子的操作是取石子,而对左棋子的操作并不会对游戏造成影响,考虑如果在 NIM 博弈时有增加石子的操作,那么下一步另一个人就可以去相同数量的石子,于是局面并没有改变. 然后就来一发异或和就行了. #include <bits/stdc++.h> using namespace std; int n,a[10005]; int mai

poj 1704 Georgia and Bob (nim)

题意: N个棋子,位置分别是p[1]...p[N]. Georgia和Bob轮流,每人每次可选择其中一个棋子向左移动若干个位置(不能超过前一个棋子,不能超出最左边[位置1]且不能不移) Georgia先手,问谁赢. 思路: 将棋子按位置从右到左两个两个作为一对.若棋子总个数是奇数,将第一个棋子和[位置0]作为一对.(可想象位置0放了一个棋子). 情况一:先手若移动某对棋子中的第一个棋子K位,则后手可将该对棋子中的第二个棋子也移动K位.即这种情况不对结果产生影响. 情况二:先手若移动某对棋子中的第

[原博客] POJ 1704 Georgia and Bob

题目链接题意:如图,Georgia和Bob在玩游戏.一个无限长的棋盘上有N个旗子,第i个棋子的位置可以用Pi表示.现在Georgia先走.每个人每一次可以把一枚棋子向左移动任意个格子,但是不能超越其他棋子,也不能和其他棋子处在同一个格子里.如果轮到某一个人的时候Ta再也不能移动棋子了,就判负.现在每个测试数据给定一种情况,如果Georgia会赢,输出“Georgia will win”,如果Bob会赢,输出“Bob will win”,如果不确定,输出“Not sure”.两个人都知道获胜策略是

poj 1704 Georgia and Bob(阶梯博弈)

Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8656   Accepted: 2751 Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, number the grids from left to right by 1, 2, 3, ...

POJ - 1704 Georgia and Bob

Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, number the grids from left to right by 1, 2, 3, -, and place N chessmen on different grids, as shown in the following figure for example: Georgia and