LightOJ 1186 Icreable Chess(Nim博弈)
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 ;
}
LightOJ 1186 Icreable Chess(Nim博弈)的更多相关文章
- LightOJ - 1247 Matrix Game (Nim博弈)题解
题意: 给一个矩阵,每一次一个玩家可以从任意一行中选任意数量的格子并从中拿石头(但最后总数要大于等于1),问你谁赢 思路: 一开始以为只能一行拿一个... 将每一行石子数相加就转化为经典的Nim博弈 ...
- LightOJ 1253 Misere NIM(反NIM博弈)
Alice and Bob are playing game of Misère Nim. Misère Nim is a game playing on k piles of stones, eac ...
- nim博弈 LightOJ - 1253
主要是写一下nim博弈的理解,这个题有点奇怪,不知道为什么判断奇偶性,如果有大佬知道还请讲解一下. //nim博弈 //a[0]~a[i] 异或结果为k 若k=0 则为平衡态 否则为非平衡态 //平衡 ...
- HDU 2509 Nim博弈变形
1.HDU 2509 2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...
- HDU 1907 Nim博弈变形
1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...
- zoj3591 Nim(Nim博弈)
ZOJ 3591 Nim(Nim博弈) 题目意思是说有n堆石子,Alice只能从中选出连续的几堆来玩Nim博弈,现在问Alice想要获胜有多少种方法(即有多少种选择方式). 方法是这样的,由于Nim博 ...
- hdu 1907 John&& hdu 2509 Be the Winner(基础nim博弈)
Problem Description Little John is playing very funny game with his younger brother. There is one bi ...
- 关于NIM博弈结论的证明
关于NIM博弈结论的证明 NIM博弈:有k(k>=1)堆数量不一定的物品(石子或豆粒…)两人轮流取,每次只能从一堆中取若干数量(小于等于这堆物品的数量)的物品,判定胜负的条件就是,最后一次取得人 ...
- HDU - 1850 Nim博弈
思路:可以对任意一堆牌进行操作,根据Nim博弈定理--所有堆的数量异或值为0就是P态,否则为N态,那么直接对某堆牌操作能让所有牌异或值为0即可,首先求得所有牌堆的异或值,然后枚举每一堆,用已经得到的异 ...
随机推荐
- ToolStrip控件左右拖拽移动效果实现
1.主窗体下部添加一个Panel乘放ToolStrip控件以实现ToolStrip在窗体下部定位.2.当ToolStrip控件中子控件超出屏幕时,拖动控件可以实现滑动效果.拖动到控件边缘距窗体边缘1/ ...
- CentOS7 编码编译安装或卸载http2.4.25 一键脚本
待完善 CentOS 7测试 哈哈 #!/bin/bash #************************************************************** #Autho ...
- 使用CBrother的CLIB库调用windows的API
使用CBrother的CLIB库调用windows的API 2.1.0版本CBrother加入了CLib库,最新需要写一个工具,根据路径查杀一个Windows进程,研究了一下,CLib库的用法,感觉还 ...
- web开发基本概念
一.什么是静态页面,什么是动态页面? 答:静态页面是不需要网络请求就可以看到的页面,保存在本地. 动态页面是需要网络请求才可以看到的页面,保存在服务器. 二.网页的运行环境? 答:浏览器 客户端 三. ...
- 网站搭建-虚拟机的使用-Linux (包括输入法和QQ下载使用)
之前已经联网了,基本的软件系统会自己下载,先不用管. 1. 先下载一个中文输入法吧: 先改一下Firefox的搜索引擎吧,因为大陆不支持google 下载,安装,就完事了,还好这个没变,几年不用这个系 ...
- PHP 中四大经典排序算法
1.冒泡排序 在要排序的一组数中,对当前还未排好的序列,从前往后对相邻的两个数依次进行比较和调整,让较大的数往下沉,较小的往上冒.即,每当两相邻的数比较后发现它们的排序与排序要求相反时,就将它们互换. ...
- [内部类] java笔记之内部类
1.内部类的分类 2.成员内部类的定义格式 3.一旦使用了内部类,那么生成的class文件长啥样? 其中Body是外部类,Heart是Body的内部类,所以中间有个美元符号$,所以给类进行命名时,不要 ...
- nyoj 22-素数求和问题(打表)
22-素数求和问题 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:41 submit:52 题目描述: 现在给你N个数(0<N<1000 ...
- C#实现整型数据字任意编码任意进制的转换和逆转换
实现如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespa ...
- 部署k8s集群监控Heapster
git clone https://github.com/kubernetes/heapster.gitkubectl apply -f heapster/deploy/kube-config/inf ...