A. PawnChess
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Sample test(s)
Input
........
........
.B....B.
....W...
........
..W.....
........
........
Output
A
Input
..B.....
..W.....
......B.
........
.....W..
......B.
........
........
Output
B
Note

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的更多相关文章

  1. Codeforces Round #328 (Div. 2) A. PawnChess 暴力

    A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...

  2. Codeforces Round #328 (Div. 2)

    这场CF,准备充足,回寝室洗了澡,睡了一觉,可结果...   水 A - PawnChess 第一次忘记判断相等时A先走算A赢,hack掉.后来才知道自己的代码写错了(摔 for (int i=1; ...

  3. Codeforces Round #328 (Div. 2) D. Super M

    题目链接: http://codeforces.com/contest/592/problem/D 题意: 给你一颗树,树上有一些必须访问的节点,你可以任选一个起点,依次访问所有的必须访问的节点,使总 ...

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

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

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

  7. Codeforces Round #328 (Div. 2) A

    A. PawnChess time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

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

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

随机推荐

  1. 用C#写入Excel表并保存

    想用C#操作Excel表,首先要做一些准备工作. 如果要操作 microsoft office Excel 2003表,就需要引入Microsoft office 11.0 object librar ...

  2. IntelliJ IDEA如何设置头注释,自定义author和date

    下面这张图,保证你一看就会: 下面这个模板,你拿去改一改就行了. /** * @Author: Gosin * @Date: ${DATE} ${TIME} */ 如果觉得上面名字下面的波浪线碍眼,可 ...

  3. Wincc flexable的局势视图的组态

    1.趋势视图介绍 2.实时趋势视图的组态 1)创建连接和变量 2)开始组态局势视图 3)设置趋势视图的属性,添加一个趋势 3.模拟运行HMI,观察局势图

  4. jstree 学习

    最近的项目用到了jstree,因为对官方文档理解不充分,所以很多功能都是在网站上搜索再进行使用的.(我只是大自然的搬运工) 对每一级的节点,右键后出现不同的结果. 在jstree中右键是由 conte ...

  5. 全国交通咨询系统 by C++ on Linux

    信息存储 利用邻接表存储城市信息与线路信息,比邻接矩阵更加高效. 主要数据结构 I)Time,规范时间的输入输出格式 II)VNode,头结点,用于建立顶点表,存储城市信息 III)ArcNode,表 ...

  6. mysql 编写存储过程

    先看例子: 1.delimiter $$2.drop procedure if exists`test_procedure` $$3.create procedure test_procedure(I ...

  7. SQL SERVER 常用知识整理

    以前写了一些关于sql的文章,包括一些转载的,这里做下整理,方便需要时候使用 一.基础运用 SQL 数据结构操作语句 SQL 时间处理 SQL 常见函数使用 CASE WHEN THEN 小结 二.优 ...

  8. Micro Templating源码分析

    关于模板,写页面的人们其实一直在用,asp.net , jsp , php, nodejs等等都有他的存在,当然那是服务端的模板. 前端模板,作为前端人员肯定是多少有接触的,Handlebars.js ...

  9. linux中搭建solr集群出现org.apache.catalina.LifecycleException: Failed to initialize component ,解决办法

    07-Jan-2018 20:19:21.489 严重 [main] org.apache.catalina.core.StandardService.initInternal Failed to i ...

  10. Python File flush方法应用

    # flush()使用# #!/usr/bin/python# # -*- coding: UTF-8 -*-## # 打开文件# fo = open("runoob.txt", ...