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.

Examples
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先手 白棋 向上向第一列前进 黑棋向下向第八列前进  谁先到达谁获胜

题解: 暴力枚举每列的黑棋或白棋 寻找 黑棋与白棋的最短路径  相同时 白棋胜

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#define ll __int64
#define pi acos(-1.0)
using namespace std;
char mp[][];
int max1,max2;
int main()
{
max1=;
max2=;
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
scanf("%c",&mp[i][j]);
}
getchar();
}
for(int i=;i<=;i++)
{
for(int j=;j<=&&mp[j][i]!='B';j++)
{
if(mp[j][i]=='W')
{
max1=min(max1,j-);
break;
}
}
}
for(int i=;i<=;i++)
{
for(int j=;j>=&&mp[j][i]!='W';j--)
{
if(mp[j][i]=='B')
{
max2=min(max2,-j);
break;
}
}
}
if(max1<=max2)
cout<<"A"<<endl;
else
cout<<"B"<<endl;
return ;
}

Codeforces Round #328 (Div. 2) A的更多相关文章

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

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

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

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

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

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

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

  6. Codeforces Round #328 (Div. 2)

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

  7. Codeforces Round #328 (Div. 2)_B. The Monster and the Squirrel

    B. The Monster and the Squirrel time limit per test 1 second memory limit per test 256 megabytes inp ...

  8. Codeforces Round #328 (Div. 2)_A. PawnChess

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

  9. Codeforces Round #328 (Div. 2) C 数学

    C. The Big Race time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. django开发傻瓜教程-3-celery异步处理

    Ref: https://www.jianshu.com/p/6f8576a37a3e https://blog.csdn.net/Demo_3/article/details/78119951 ht ...

  2. 005---Python数据类型--字典

    字典 .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px ...

  3. 当app出现线上奔溃,该如何办?

    1.如何追踪app崩溃率,如何解决线上闪退 当iOS设备上的App应用闪退时,操作系统会生成一个crash日志,保存在设备上.crash日志上有很多有用的信息,比如每个正在执行线程的完整堆栈跟踪信息和 ...

  4. kettle 遇到 解决Incorrect integer value: '' for column 'id' at row 1 完美解决-费元星

    最近自己在测试一个开源的程序,测试中发现.该程序都添加和更新的时候回出现 Incorrect integer value: '' for column 'id' at row 1类是的错误! 后来我自 ...

  5. jmeter对请求参数的签名处理

    1.首先在本地写好签名的算法,本文采用RSA签名. public final class Base64 { static private final int BASELENGTH = 128; sta ...

  6. docker简单命令

    查看镜像 docker images 查看正在使用的容器 docker ps -a 进入容器控制台 docker exec -it 容器ID bash 启动镜像 docker run -it -d.. ...

  7. centos7安装python3.7

    Centos7安装Python3的方法   由于centos7原本就安装了Python2,而且这个Python2不能被删除,因为有很多系统命令,比如yum都要用到. [root@VM_105_217_ ...

  8. CentOS7 Zabbix4.0环境下的安装和配置实例

    1.安装准备 Zabbix4.0对基础架构有一定的要求,对的英文尤其PHP状语从句:MySQL: 类型 内容 服务端运行环境 Linux和PHP与Web服务器和数据库 服务端操作系统 CentOS7. ...

  9. 时间动态协同过滤(TimeSVD++)

    原作者 原论文地址 http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.379.1951&rep=rep1&type=pd ...

  10. 使用idea工具开发webservice

    在idea开发工具中使用axis2插件创建集成webservice的web项目: 一.创建java项目                  二.添加webservices支持 在红线框2处选择要使用的w ...