这还是一道博弈的题目,但是我没有思路,。开始我想的是把它转化为取石子的问题,直接就是将每一个放的棋子的位置然后再看它到自己最终的位置的长度,就将其抽象成第几堆的棋子的个数,后来发现这是错误的,也还是我对昨天的nim的理解太浅显了。。。对于奇异局势的理解不够好。其实对于每一个博弈的问题我最开始需要找到的是它的奇异局势,而不是最终的状态。这个题目的求解是这样的。就是两两组合,当两者相邻的时候就是奇异局势,就是这个小范围的奇异局势。因为当这以后前面的人无论怎样走,后面的人只要跟着他走就好了。所以当N为偶数时,两两组合,当n为奇数的时候则是最前面的那个棋子与最左边的墙壁组合。这样,两两之间的距离就是相当于取的石子数。
真心不会,其实这道题目在博弈里面算简单的但是可能是刚接触博弈吧,没有看懂,昨天想了一天加一晚上才理解了。。。。加到b【0】,和不加其实本质没什么区别,只是控制加的位置而已,便于控制两两一组
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 Bob move the chessmen in turn. Every time a player will choose a chessman, and move it to the left without going over any other chessmen or across the left edge. The player can freely choose number of steps the chessman moves, with the constraint that the chessman must be moved at least ONE step and one grid can at most contains ONE single chessman. The player who cannot make a move loses the game.
Georgia always plays first since "Lady first". Suppose that Georgia and Bob both do their best in the game, i.e., if one of them knows a way to win the game, he or she will be able to carry it out.
Given the initial positions of the n chessmen, can you predict who will finally win the game?
Georgia and Bob move the chessmen in turn. Every time a player will choose a chessman, and move it to the left without going over any other chessmen or across the left edge. The player can freely choose number of steps the chessman moves, with the constraint that the chessman must be moved at least ONE step and one grid can at most contains ONE single chessman. The player who cannot make a move loses the game.
Georgia always plays first since "Lady first". Suppose that Georgia and Bob both do their best in the game, i.e., if one of them knows a way to win the game, he or she will be able to carry it out.
Given the initial positions of the n chessmen, can you predict who will finally win the game?
Input
The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. Each test case contains two lines. The first line consists of one integer N (1 <= N <= 1000), indicating the number of chessmen. The second line contains N different integers P1, P2 ... Pn (1 <= Pi <= 10000), which are the initial positions of the n chessmen.
Output
For each test case, prints a single line, "Georgia will win", if Georgia will win the game; "Bob will win", if Bob will win the game; otherwise 'Not sure'.
Sample Input
2 3 1 2 3 8 1 5 6 7 9 12 14 17
Sample Output
Bob will win Georgia will win
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int a[1010],b[1010];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
b[0]=0;
scanf("%d",&n);
for(int i=1; i<=n; i++)
scanf("%d",&a[i]);
sort(a+1,a+n+1);
for(int i=1; i<=n; i++)
b[i]=a[i]-a[i-1]-1;
int s=0;
for(int i=n; i>0; i-=2)
s^=b[i];
if(s==0)
puts("Bob will win");
else
puts("Georgia will win");
}
return 0;
}