codeforces PawnChess
来源:互联网 发布:java messagedigest 编辑:程序博客网 时间:2024/05/16 10:53
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.
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.
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.
.................B....B.....W.............W.....................
A
..B.......W...........B..............W........B.................
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.
题意:找出最先到达上边界或下边界的人
#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#define inf 0x3f3f3f3fusing namespace std;char map[10][10];int MIN(int a,int b){return a<b?a:b;}int main(){int i,j,k;for(i=0;i<8;++i){scanf("%s",map[i]);}int mina=inf,minb=inf;for(i=0;i<8;++i){for(j=0;j<8;++j){if(map[j][i]!='.'){if(map[j][i]=='W'){mina=MIN(mina,j);break;}else break;}}}for(i=0;i<8;++i){for(j=7;j>=0;--j){if(map[j][i]!='.'){if(map[j][i]=='B'){minb=MIN(minb,8-j);break;}else break;}}}if(mina<minb)printf("A\n");else printf("B\n");return 0;}
- codeforces PawnChess
- Codeforces 592A. PawnChess
- Codeforces 592A PawnChess 【水题】
- PawnChess
- Codeforces Round #328 (Div. 2)_A. PawnChess
- Codeforces Round #328 (Div. 2) A PawnChess
- Codeforces Round #328 (Div. 2)A. PawnChess
- Codeforces Round #328 (Div. 2) A. PawnChess
- Codeforces Round #328 (Div. 2) A. PawnChess
- PawnChess (Codeforces Round #328 (Div. 2) )
- Codeforces Round #328 (Div. 2)A. PawnChess
- Codeforces 592 A. PawnChess 【Codeforces Round #328 (Div. 2)】
- Codeforces Round #328 (Div. 2)Problem A. PawnChess(模拟)
- Codeforces Round #328 (Div. 2) 592A PawnChess
- A. PawnChess
- 【Codeforces Round 328 (Div 2)A】【水题】PawnChess 棋子向上向下走
- PawnChess(模拟)
- cf#328-A. PawnChess-水题
- Formal System-范式(Normalformen)
- merge interval leetcode java
- 软件定义存储(SDS)的定义及其分类
- 字符串四则运算之一无限位数相加的设计
- 字符串四则运算之二无限位数相减的设计
- codeforces PawnChess
- 字符串四则运算之三无限位数相乘的设计
- 字符串四则运算之四无限位数相除的设计
- codeforces B. The Monster and the Squirrel
- Android性能优化典范
- BC 61 Numbers
- UESTC1218 2015CCPC DP 0,1背包
- Editplus和Notepad++设置默认编码
- BC 61 Game