CF592A.PawnChess
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
加洛瓦是字节力场(Byteforces)最强的国际象棋选手之一。他甚至发明了一种新的国际象棋变体,命名为「兵棋」(PawnChess)。
这种新棋类游戏在一个 8 行 × 8 列的棋盘上进行。每局游戏开始时,棋盘上会放置若干枚黑兵和白兵。黑兵的数量与白兵的数量不一定相等。

我们用从 1 到 8 的整数对行与列进行编号:行号自上而下递增,列号从左至右递增。记位于第 r 行、第 c 列的格子为 (r,c)。
游戏中始终有两位玩家 A 和 B 参与对弈:玩家 A 操控白兵,玩家 B 操控黑兵。玩家 A 的目标是将其任意一枚白兵移动至第 1 行;玩家 B 的目标则是将其任意一枚黑兵移动至第 8 行。一旦任一玩家达成其目标,游戏立即结束,该玩家即为胜者。
玩家 A 先手,之后双方轮流行动。在自己的回合中,玩家 A 必须且仅能选择一枚白兵,将其向上移动一格;玩家 B(在其回合中)则必须且仅能选择一枚黑兵,将其向下移动一格。任何移动仅当目标格子为空时才被允许。题目保证:对于任意可能的游戏局面,双方中至少有一方总存在合法的可行动作。
“向上移动”指位于 (r,c) 的兵移至 (r−1,c);“向下移动”指位于 (r,c) 的兵移至 (r+1,c)。再次强调:目标格子必须为空,即不能被任何颜色的其他兵占据。
给定棋盘的初始布局,请判断:若双方均以最优策略进行游戏,谁将获胜?注意:由于题目保证在任意游戏进程中双方始终至少存在一个合法动作,因此必有胜者。
输入格式
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.
输入包含八行棋盘描述,每行包含八个字符。字符 'B' 表示黑方兵,字符 'W' 表示白方兵,空格用 '.' 表示。
保证第一行不会出现白方兵,最后一行不会出现黑方兵。
输出格式
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.
如果玩家 A 在给定棋盘上赢得游戏,则输出 'A';如果玩家 B 将获得胜利,则输出 'B'。同样保证:在给定棋盘上总会有胜者。
输入输出样例
输入#1
........ ........ .B....B. ....W... ........ ..W..... ........ ........
输出#1
A
输入#2
..B..... ..W..... ......B. ........ .....W.. ......B. ........ ........
输出#2
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 可以通过始终移动初始位于 (4, 5) 的兵,在 3 步内完成其目标。而玩家 B 的任意一个兵到达第 8 行至少需要 5 步。因此,玩家 A 将获胜。
输入解题思路,AI测评打分。不知道怎么写?