题目链接:http://lightoj.com/volume_showproblem.php?problem=1186
Time Limit: 2 second(s) Memory Limit: 32 MB

Problem Description

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

Output for Sample Input

Case 1: black wins
Case 2: white wins

Problem solving report:

Description: n*n的棋盘,有黑白棋子,只能上下移动,不能移动的输,白棋先手,判断输赢。
Problem solving: 把每一列的棋子间隔(可以走的地方)看成Nim博弈中的石子数量,将N堆石子数量异或,若结果为0,先手必败。

Accepted Code:

/* 
 * @Author: lzyws739307453 
 * @Language: C++ 
 */
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int spt[MAXN];
int main() {
    int t, n, m, kase = 0;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
            scanf("%d", &spt[i]);
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d", &m);
            spt[i] = m - spt[i] - 1;
            cnt ^= spt[i];
        }
        if (!cnt)
            printf("Case %d: black wins\n", ++kase);
        else printf("Case %d: white wins\n", ++kase);
    }
    return 0;
}