POJ Georgia and Bob-----阶梯博弈变形。

本文探讨了Georgia和Bob进行的一种自创棋盘游戏的策略。玩家需要通过移动棋子来预测最终的赢家。游戏涉及奇偶数转换为Nim游戏,通过排序和异或操作来判断胜者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Georgia and Bob
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 6622 Accepted: 1932

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?  

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

Source

 1 /*
 2 
 3 如上如图所示:排成直线的格子上有n个格子,棋子i在左数第pi个格子上。
 4 G和B轮流选择一个棋子向左移动。每次移动可以移动一格及以上任意多个格,
 5 但是不允许超其他的格子,也不允许将两个棋子放在同一个格子内。
 6 无法移动就失败了。~~
 7 
 8 转化:
 9 如果将棋子两两看出一个整体考虑,我们就可以把这个游戏转为Nim游戏。
10 先将棋子的个数的奇偶分情况讨论。
11      偶数:___1____5____8______10
12      就可以转化为  第一堆 5-1-1=3 个
13                    第二堆 10-8-1=1 个。
14                    
15      为什么能这样转化?
16      考虑其中的一对棋子,将右边的棋子向左移动就相当于从Nim的石子堆中
17      取走石子
18      另一方面,将左边的棋子向左移动,石子的数量就增加了。这就与Nim不同。
19      但是,即便对手增加了石子的数量,只要将所加部分减回去就回到了原来的
20      状态;即便增加了石子的数量,只要对手将所加的部分减回去也就回到原来
21      状态了。
22      
23      奇数:将最左边的0看出起始点就转化成偶数个了。
24 */
25 
26 #include<iostream>
27 #include<cstdio>
28 #include<cstdlib>
29 #include<algorithm>
30 using namespace std;
31 
32 int f[1003];
33 int main()
34 {
35     int T,n,i,k,hxl;
36     while(scanf("%d",&T)>0)
37     {
38         while(T--)
39         {
40             scanf("%d",&n);
41             for(i=1;i<=n;i++)
42             scanf("%d",&f[i]);
43             if(n%2==1)
44             f[++n]=0;
45             k=0;
46             sort(f+1,f+1+n);
47             for(i=n;i>=1;i=i-2)
48             k=k^(f[i]-f[i-1]-1);
49             if(k==0)
50             printf("Bob will win\n");
51             else printf("Georgia will win\n");
52         }
53     }
54     return 0;
55 }

 

转载于:https://www.cnblogs.com/tom987690183/p/3248575.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值