BNUOJ 13105 nim博弈

ncredible Chess

Time Limit: 2000ms
Memory Limit: 32768KB
This problem will be judged on LightOJ. Original ID: 1186
64-bit integer IO format: %lld      Java class name: Main

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.

 

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. Wimeans 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

Sample Input

Output for 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

Case 1: black wins

Case 2: white wins

Source

题意:n*n的棋盘 黑白棋子 只能左右移动 不能移动的输 白棋先手
题解:尼姆博弈  将同一行的黑白棋子的间隔位置数量当作 经典题目中每一堆石子的数量 直接求取异或和
 1 /******************************
 2 code by drizzle
 3 blog: www.cnblogs.com/hsd-/
 4 ^ ^    ^ ^
 5  O      O
 6 ******************************/
 7 #include<bits/stdc++.h>
 8 #include<map>
 9 #include<set>
10 #include<cmath>
11 #include<queue>
12 #include<bitset>
13 #include<math.h>
14 #include<vector>
15 #include<string>
16 #include<stdio.h>
17 #include<cstring>
18 #include<iostream>
19 #include<algorithm>
20 #pragma comment(linker, "/STACK:102400000,102400000")
21 using namespace std;
22 #define  A first
23 #define B second
24 const int mod=1000000007;
25 const int MOD1=1000000007;
26 const int MOD2=1000000009;
27 const double EPS=0.00000001;
28 typedef __int64 ll;
29 const ll MOD=1000000007;
30 const int INF=1000000010;
31 const ll MAX=1ll<<55;
32 const double eps=1e-8;
33 const double inf=~0u>>1;
34 const double pi=acos(-1.0);
35 typedef double db;
36 typedef unsigned int uint;
37 typedef unsigned long long ull;
38 int t;
39 int a[105];
40 int b[105];
41 int n;
42 int ans;
43 int main()
44 {
45     scanf("%d",&t);
46     for(int i=1; i<=t; i++)
47     {
48         scanf("%d",&n);
49         for(int j=1; j<=n; j++)
50             scanf("%d",&a[j]);
51         for(int j=1; j<=n; j++)
52             scanf("%d",&b[j]);
53         ans=0;
54         for(int j=1; j<=n; j++)
55         {
56             if(a[j]>b[j])
57             ans=ans^(a[j]-b[j]-1);
58             else
59             ans=ans^(b[j]-a[j]-1);
60         }
61         if(ans==0)
62             printf("Case %d: black wins
",i);
63         else
64             printf("Case %d: white wins
",i);
65     }
66     return 0;
67 }
原文地址:https://www.cnblogs.com/hsd-/p/6013499.html