题目链接:http://lightoj.com/volume_showproblem.php?problem=1186
You are given an n x n chess board. Only pawn is used in the 'Incredible Chess' and they can move forward or backward. In each column there are two pawns, one white and one black. White pawns are placed in the lower part of the board and the black pawns are placed in the upper part of the board.
The game is played by two players. Initially a board configuration is given. One player uses white pieces while the other uses black. In each move, a player can move a pawn of his piece, which can go forward or backward any positive integer steps, but it cannot jump over any piece. White gives the first move.
The game ends when there is no move for a player and he will lose the game. Now you are given the initial configuration of the board. You have to write a program to determine who will be the winner.
Example of a Board
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case starts with an integer n (3 ≤ n ≤ 100) denoting the dimension of the board. The next line will contain n integers, W0, W1, ..., Wn-1 giving the position of the white pieces. The next line will also contain n integers, B0, B1, ... Bn-1 giving the position of the black pieces. Wi means the row position of the white piece of ith column. And Bi means the row position of the black piece of ith column. You can assume that (0 ≤ Wi < Bi < n) for (0 ≤ i < n) and at least one move is remaining.
Output
For each case, print the case number and 'white wins' or 'black wins' depending on the result.
Sample Input
2
6
1 3 2 2 0 1
5 5 5 3 1 2
7
1 3 2 2 0 4 0
3 4 4 3 1 5 6
Sample Output
Case 1: black wins
Case 2: white wins
题目翻译:
您将获得一个n x n棋盘。只有棋子在"难以置信的国际象棋"中使用,他们可以向前或向后移动。每列中有两个棋子,一个白色,一个黑色。白色棋子被放置在棋盘的下部,黑色棋子被放置在棋盘的上部。
游戏由两位玩家玩。最初给出了一个板配置。一个玩家使用白棋子,而另一个玩家使用黑色。在每一个动作中,玩家可以移动棋子,可以向前或向后任何正整数步骤,但不能跳过任何棋子。怀特给出了第一个动作。
当玩家没有移动时,游戏结束,他将会输掉比赛。现在,您获得了主板的初始配置。你必须写一个程序,以确定谁将是赢家。
董事会示例
输入
输入以整数T(=200)开头,表示测试用例的数量。
每个案例都以表示电路板尺寸的整数n (3 = n = 100)开头。下一行将包含n个整数,W 0,W1 ,...,Wn-1给出白段的位置。下一行还将包含n整数、B 0、B1...。Bn-1给出黑片的位置。Wi表示第 i 列的白色部分的行位置。和 Bi表示第 i 列黑色部分的行位置。您可以假定(0 = Wi i < Bi < n)对于(0 = i < n)和至少一个移动是剩余。
输出
对于每个案例,打印案例编号和"白赢"或"黑赢",具体取决于结果。
尼姆博弈的变形题,把每一列黑子与白子之间的空白个数转换成石子的数量,判断输出结果就行了,
#include<iostream>
using namespace std;
int a[105],b[105];
int main(){
int T;
scanf("%d",&T);
for(int kcase=1;kcase<=T;kcase++){
int n;
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
for(int i=1;i<=n;++i)
scanf("%d",&b[i]);
int sum=0;
for(int i=1;i<=n;++i){
sum^=(b[i]-a[i]-1);
}
if(sum) printf("Case %d: white wins\n",kcase);
else printf("Case %d: black wins\n",kcase);
}
return 0;
}