Codeforces Round #328 (Div. 2)_A. PawnChess
1 second
256 megabytes
standard input
standard output
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed.

Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as
(r, c) the cell located at the row
r and at the column
c.
There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row
1, while player B tries to put any of his pawns to the row
8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.
Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if
 the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.
Moving upward means that the pawn located in (r, c) will go to the cell
(r - 1, c), while moving down means the pawn located in
(r, c) will go to the cell
(r + 1, c). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.
Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.
The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents
 a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.
Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.
........
........
.B....B.
....W...
........
..W.....
........
........
A
..B.....
..W.....
......B.
........
.....W..
......B.
........
........
B
In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at
(4, 5). Player B needs at least 5 steps for any of his pawns to reach the row
8. Hence, player A will be the winner.
/*题目大意:A与B下棋,A只能向上走、B只能向下,谁先到达最顶端或最低端谁胜
* 这里注意的是A先走 */ #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring> using namespace std; int main() {
char a[8][8];
memset(a, 0, sizeof(a));
for (int i = 0; i<8; i++) {
for (int j = 0; j<8; j++) {
cin>> a[i][j];
}
}
int num1 = 100, num2 = 100;
int flag = 1;
for (int i = 0; i<8; i++) {
for (int j = 0; j<8; j++) {
flag = 1;
if (a[i][j] == 'W') {
for (int k = i-1; k>=0; k--) {
if (a[k][j] != '.')
flag = 0;
}
if (flag == 1) {
if (i < num1)
num1 = i;
}
}
flag = 1;
if (a[i][j] == 'B') {
for (int k = i+1; k<8; k++) {
if (a[k][j] != '.')
flag = 0;
}
if (flag == 1) {
if ((8-i-1) < num2)
num2 = 8-i-1;
}
}
}
}
if (num1 <= num2) //步数相等则A胜
cout << "A"<< endl;
else
cout << "B"<< endl; return 0;
}
Codeforces Round #328 (Div. 2)_A. PawnChess的更多相关文章
- Codeforces Round #328 (Div. 2) A. PawnChess 暴力
		
A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...
 - Codeforces Round #328 (Div. 2)
		
这场CF,准备充足,回寝室洗了澡,睡了一觉,可结果... 水 A - PawnChess 第一次忘记判断相等时A先走算A赢,hack掉.后来才知道自己的代码写错了(摔 for (int i=1; ...
 - Codeforces Round #328 (Div. 2) D. Super M
		
题目链接: http://codeforces.com/contest/592/problem/D 题意: 给你一颗树,树上有一些必须访问的节点,你可以任选一个起点,依次访问所有的必须访问的节点,使总 ...
 - Codeforces Round #328 (Div. 2) D. Super M 虚树直径
		
D. Super M Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/D ...
 - Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm
		
C. The Big Race Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/probl ...
 - Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学
		
B. The Monster and the Squirrel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...
 - Codeforces Round #328 (Div. 2) A
		
A. PawnChess time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
 - Codeforces Round #347 (Div.2)_A. Complicated GCD
		
题目链接:http://codeforces.com/contest/664/problem/A A. Complicated GCD time limit per test 1 second mem ...
 - Codeforces Round #331 (Div. 2) _A. Wilbur and Swimming Pool
		
A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes input s ...
 
随机推荐
- Qt之移动硬盘热插拔监控
			
最近在做一个通用对话框,类似于windows的资源管理器,当然了没有windwos资源管理器那么强大.用户报了一个bug,说通用对话框打开之后不能实时监控U盘插入,随手在百度上搜索了一圈,这个问题还是 ...
 - Find Unique pair in an array with pairs of numbers 在具有数字对的数组中查找唯一对
			
给定一个数组,其中每个元素出现两次,除了一对(两个元素).找到这个唯一对的元素. 输入:第一行输入包含一个表示测试用例数的整数T.然后T测试用例如下.每个测试用例由两行组成.每个测试用例的第一行包含整 ...
 - nginx搭建rtmp协议流媒体服务器总结
			
最近在 ubuntu12.04+wdlinux(centos)上搭建了一个rtmp服务器,感觉还挺麻烦的,所以记录下. 大部分都是参考网络上的资料. 前提: 在linux下某个目录中新建一个nginx ...
 - Windows zip安装MySQL
			
1. mysqld初始化时my.ini的第二个默认位置是%windir%/my.ini rem 1.查看此变量对应的目录,在此目录下编辑 my.ini,mysqld会自动找到 echo %WINDIR ...
 - FPGA浮点数定点化
			
因为在普通的fpga芯片里面,寄存器只可以表示无符号型,不可以表示小数,所以在计算比较精确的数值时,就需要做一些处理,不过在altera在Arria 10 中增加了硬核浮点DSP模块,这样更加适合硬件 ...
 - centos 打包RPM包 ntopng
			
需要在centos7上,将ntopng及其依赖的包一起打包成rpm包,了解centos7打包. 1.执行: yum -y install rpmdevtools 安装rpm工具 2.接下来执行:rp ...
 - CSS图片翻转动画技术详解
			
因为不断有人问我,现在我补充一下:IE是支持这种技术的!尽管会很麻烦.需要做的是旋转front和back元素,而不是旋转整个容器元素.如果你使用的是最新版的IE,可以忽略这一节.IE10+是支持的,I ...
 - 微信小程序一:微信小程序UI组件、开发框架、实用库
			
作者:NiceCui 本文谢绝转载,如需转载需征得作者本人同意,谢谢. 本文链接:http://www.cnblogs.com/NiceCui/p/8079095.html 内容持续更新,维护中 邮箱 ...
 - ADO.NET访问数据库
			
1:ADO.NET数据库的方法和技术 2:ADO.NET的主要组成: 1>DataSet(数据集)-----独立于数据间的数据访问 2>.NETFramework(数据提供程序)----- ...
 - Web开发入门学习笔记
			
公司web项目终于要启动了,本以为django学习可以在实战中进行,结果最终使用了Drupal框架,好吧,那我们就PHP走起,买了本<细说PHP>,先跟着过一遍Web开发入门. HTTP协 ...