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 ...
随机推荐
- spring boot使用profile来区分正式环境配置文件与测试环境配置文件
转载请在页首注明作者与出处 一:前言 经常在开发的时候,项目中的配置文件,在个人开发的时候有一套配置文件,在测试环境有一套配置文件,在正式环境有一套配置文件,这个时候如果配置文件复杂,需要改的东西就特 ...
- 使用VSCode创建Asp.Net Core
前言 .Net Core 2.0已经发布几个月了,惭愧!身为一个开发人员现在才开始接触,有人说有VS这一宇宙第一IDE在,为啥还要用VSCode,为啥?因为我们是程序猿啊!我们是攻城狮啊!我们爱折腾啊 ...
- 两个HC-05蓝牙模块互相绑定构成无线串口模块
HC-05 嵌入式蓝牙串口通讯模块(以下简称模块)具有两种工作模式:命令响应工作模式和自动连接工作模式,在自动连接工作模式下模块又可分为主(Master).从(Slave)和回环(Loopback)三 ...
- Linux发行版 CentOS6.5 禁用防火墙步骤
本文地址http://comexchan.cnblogs.com/,尊重知识产权,转载请注明出处,谢谢! 注意:此操作需要使用root权限执行 首先查询防火墙状态: service iptables ...
- Git_学习_03_ ignore文件配置
一.示例 # 1.Compiled class file *.class bin target # 2.Log file *.log logs # 3. Package Files # *.war * ...
- kafka 消费
前置资料 kafka kafka消费中的问题及解决方法: 情况1: 问题:脚本读取kafka 数据,写入到数据库,有时候出现MySQL server has gone away,导致脚本死掉.再次启 ...
- PHP array_map()
PHP array_map() 函数 将函数作用到数组中的每个值上,每个值都乘以本身,并返回带有新值的数组: <?php function myfunction($v) { return($v* ...
- MssqlOnLinux 备份和日志【3】
数据库恢复模式: 一 简单模式:只对数据进行备份,不备份日志. 二 完整模式:支持数据,日志备份. 三 大容量日志模式:支持数据,日志备份.适用于大规模大容量操作,用最小的方式记录大多数操作. 数据库 ...
- java 数据格式验证类
作为一个前端,懂一点java,php之类的,甚好. 我所在的项目前端采用的就是java的spring mvc框架,所以我们也写java,掐指一算,也快一年了. 前端而言,验证是一个坎,绕不过去的,前面 ...
- ajax介绍及使用
一.什么是ajax:(只刷新局部页面的技术) AJAX全称为“Asynchronous JavaScript and XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发 ...