Codeforces 592 A. PawnChess 【Codeforces Round #328 (Div. 2)】

简介:

点击打开链接


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.


题目大意:

有一个 8*8 的矩阵(棋盘),有 B 和 W ,B表示黑棋,W表示白棋,然后又两个人A和B,A拿白棋先走,

A想走到第一行,B想走到第八行,看谁先到达。。。


解题思路:

就是比较一下大小,需要注意的是如果B和W在同一列,而且B在W上面就直接跳过。。。


上代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;

#define MM(a) memset(a,0,sizeof(a))

typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 15;
const int mod = 1000000007;
const double eps = 1e10-7;
char mat[8][8];
int main()
{
    for(int i=0; i<8; i++)
        cin>>mat[i];
    int Mina = 999999, Minb = 999999;
    for(int i=0; i<8; i++)
    {
        for(int j=0; j<8; j++)
        {
            if(mat[j][i] == 'B')
                break;
            if(mat[j][i]=='W')
            {
                Mina = min(Mina, j);
                break;
            }
        }
    }
    for(int i=0; i<8; i++)
    {
        for(int j=7; j>=0; j--)
        {
            if(mat[j][i] == 'W')
                break;
            if(mat[j][i] == 'B')
            {
                Minb = min(Minb, 8-j);
                break;
            }
        }
    }
    if(Mina < Minb)
        puts("A");
    else
        puts("B");
    return 0;
}



目录
相关文章
|
27天前
|
人工智能 测试技术 芯片
Codeforces Round 963 (Div. 2)
Codeforces Round 963 (Div. 2)
|
27天前
|
人工智能 测试技术 BI
Codeforces Round 942 (Div. 2)
Codeforces Round 942 (Div. 2)
|
4月前
Codeforces Round #567 (Div. 2)
【7月更文挑战第1天】
44 7
Codeforces Round #186 (Div. 2)A、B、C、D、E
Ilya得到了一个礼物,可以在删掉银行账户最后和倒数第二位的数字(账户有可能是负的),也可以不做任何处理。
34 0
|
人工智能 索引
Codeforces Round 806 (Div. 4)
Codeforces Round 806 (Div. 4)A~G
110 0
【CodeForces】Codeforces Round 857 (Div. 2) B
【CodeForces】Codeforces Round 857 (Div. 2) B
129 0