CF div2 328 A

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.

各种题读年。。。少了个等于号然后被hack,sad...

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <stack>
 5 #include <queue>
 6 #include <map>
 7 #include <algorithm>
 8 #include <vector>
 9 
10 using namespace std;
11 
12 const int maxn = 1000005;
13 
14 typedef long long LL;
15 
16 vector<int>G[maxn];
17 
18 int a[maxn];
19 int res[maxn];
20 
21 char s[10][10];
22 
23 int vis[10][10];
24 
25 int main()
26 {
27     int n,m;
28     for(int i=0;i<8;i++){
29         scanf("%s",s[i]);
30     }
31     int ansB = 1000;
32     int ansA = 1000;
33     for(int i=0;i<8;i++){
34         for(int j=0;j<8;j++){
35             if(s[i][j] == 'B'){
36                 int step = 0;
37                 for(int k=i+1;k<8;k++){
38                     if(s[k][j] == 'W'){
39                         step = 1000;
40                         break;
41                     }
42                     step ++;
43                 }
44                 ansB = min(step,ansB);
45             }
46             if(s[i][j] == 'W'){
47                 int step1 = 0;
48                 for(int k=i-1;k>=0;k--){
49                     if(s[k][j] == 'B'){
50                         step1 = 1000;
51                         break;
52                     }
53                     step1 ++;
54                 }
55                 ansA = min(step1,ansA);
56             }
57 
58 
59         }
60 
61     }
62     if(ansA <= ansB) printf("A\n");
63     if(ansA > ansB)printf("B\n");
64 
65 
66     return 0;
67 }
View Code

 

posted @ 2015-11-02 10:47  lmlyzxiao  阅读(117)  评论(0编辑  收藏  举报