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 nintegers, 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堆石子,依次去取的NIM博弈;

参考代码:

 #include<bits/stdc++.h>
using namespace std;
const int maxn=;
int a[maxn],b[maxn];
int T,n,ans,cnt; int main()
{
scanf("%d",&T);
for(int cas=;cas<=T;cas++)
{
ans=cnt=;
scanf("%d",&n);
for(int i=;i<=n;++i) scanf("%d",&a[i]);
for(int i=;i<=n;++i) scanf("%d",&b[i]);
for(int i=;i<=n;++i)
{
a[i]=b[i]-a[i]-;
ans^=a[i];
//if(a[i]==1) cnt++;
//else ans^=a[i];
} if(!ans) printf("Case %d: black wins\n",cas);
else printf("Case %d: white wins\n",cas);
return ;
}

最新文章

  1. Android中使用ImageViewSwitcher实现图片切换轮播导航效果
  2. JQuery中的ajax应用
  3. 监听EditText变化---TextWatcher 类用法详解
  4. Externalizable接口 序列化
  5. 在Tomcat下部属项目三种方式:
  6. Golang中解析json,构造json
  7. MyEclipse中用Maven创建Web项目(亲测有效)
  8. Ajaxterm-0.10-8.el5.noarch.rpm CentOS 5 (RHEL 5) Download
  9. SpringMVC源码情操陶冶#task-executor解析器
  10. LeetCode &amp; Q28-Implement strStr-Easy
  11. 详解MariaDB数据库的触发器
  12. Nessus更新到8.3.0
  13. 常用模块 time sys os json pickle
  14. 大量删除MySQL中的数据
  15. php二分法查找
  16. java⑩
  17. Asp.net(C#)常用正则表达式封装
  18. ansible 批量推送公钥
  19. 小程序中 function (res)的理解
  20. selenium,unittest——驾照科目一网上答题自动化

热门文章

  1. Eclipse对Java项目打Jar包
  2. Spring 应用之Spring JDBC实现
  3. c#Func委托
  4. 那些年用过的UI开发平台
  5. Nginx做缓存服务器
  6. Geometry 判断几何是否被另一个几何/线段分割成多段
  7. nyoj 111-分数加减法 (gcd, switch, 模拟,数学)
  8. java的Io流机制的学习
  9. 20191010-5 alpha week 1/2 Scrum立会报告+燃尽图 03
  10. 窗体的FormBorderStyle属性的不同效果