Description
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 was played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns is placed on the board. The number of black pawns placed is isn't necessarily equal to the number of white pawns placed.
Lets Enumerate rows and columns with integers from 1 to 8. Rows is numbered from the top to the bottom, while columns is numbered from. Now we denote as (R, C) The cell located at the row R and at the column C.
There is always players A and B playing the game. Player A plays with the white pawns, while the player B plays with black ones. The goal of player A is to put any of the pawns to the row 1, and while player B tries to put any of the his pawns to the row 8. As soon as any of the players completes he goal the game finishes immediately and the succeeded player is declared A winner.
Player A moves first and then they alternate turns. On he 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 was possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there would always be at least one move available for any of the players.
Moving upward means that the pawn located in (R, C) would go to the cell (R -1, c ), while moving down means the pawn located in (R, C) would go to the cell (R + 1, c). Again, the corresponding cell must is empty, i.e. not occupied by any and pawn of any color.
Given the initial disposition of the Board, determine who wins the game if both players play optimally. Note that there would always is a winner due to the restriction so for any game scenario both players would have some move S available.
Input
The input consists of the board description given in eight lines, each line contains eight characters. Character 'B ' is used-denote a black pawn, and Character 'W ' represents a white pawn. Empty cell is marked with '. '.
It's guaranteed that there is not being 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 would claim the victory. Again, it ' s guaranteed that there would 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 was able to complete he goal in 3 steps by all moving A Pawn initially located at (4, 5). Player B needs at least 5 steps for any of its pawns to reach the row 8. Hence, player A'll be the winner.
According to test instructions, we are looking for W B to the boundary who is the shortest, nature is to traverse once, find after, look for them on the road there is no highway, no record shortest ~ The topic said there will be a path, there will be no blocking the situation ~
#include <bits/stdc++.h>using namespace Std;int main () {char c[1000][1000]; int n=1000,m=1000; for (int i=1;i<=8;i++) {for (int j=1;j<=8;j++) {cin>>c[i][j]; }} for (int i=1;i<=8;i++) {for (int j=1;j<=8;j++) {if (c[i][j]== ' W ') { int flag1=0; for (int k=i-1;k>=1;k--) {//cout<<c[k][j]<< "C" <<endl; if (c[k][j]!= '. ') {flag1=1; Break }}//cout<<flag1<< "A" <<endl; cout<<i<< "B" <<endl; if (flag1==0) {n=min (n,i-1); }} if (c[i][j]== ' B ') {int flag2=0; for (int k=i+1;k<=8;k++) { if (c[k][j]!= '. ') {flag2=1; Break }} if (flag2==0) {m=min (m,8-i); }}}}//cout<<n<<endl; cout<<m<<endl; if (n<=m) {puts ("A"); } else {puts ("B"); } return 0;}
Codeforces Round #328 (Div. 2) A