Codeforces Round #328 (Div. 2)A. PawnChess
来源:互联网 发布:分期付款算法 编辑:程序博客网 时间:2024/04/27 20:03
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.
题目大意:
A和B两个人下棋,A用白棋,B用黑棋,当a的棋子到达最顶上时a赢,当b的棋子到达最下面时b赢,有棋子挡住不能前进,a先手问a,b谁胜;
解题思路:
简单,模拟即可
代码:
#include "iostream"#include "cstdio"#include "string.h"#include "vector"#include "math.h"using namespace std;char map[10][10];int main(int argc, char* argv[]){ int a=10,b=10; for(int i=1;i<=8;i++) for(int j=1;j<=8;j++) cin>>map[i][j];for(int i=1;i<=8;i++){ for(int j=1;j<=8;j++){if(map[i][j]=='W'){bool flag=true;for(int k=i-1;k>0;k--){if(map[k][j]!='.'){flag=false;break;}}if(flag)a=min(a,i-1);}if(map[i][j]=='B'){bool flag=true;for(int k=i+1;k<=8;k++){if(map[k][j]!='.'){flag=false;break;}}if(flag)b=min(b,8-i);}}} if(a>b) printf("B\n"); else printf("A\n"); return 0;}
- 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
- Codeforces 592 A. PawnChess 【Codeforces Round #328 (Div. 2)】
- Codeforces Round #328 (Div. 2)Problem A. PawnChess(模拟)
- Codeforces Round #328 (Div. 2) 592A PawnChess
- Codeforces Round #328 (Div. 2)_A. PawnChess
- PawnChess (Codeforces Round #328 (Div. 2) )
- 【Codeforces Round 328 (Div 2)A】【水题】PawnChess 棋子向上向下走
- cf 328 div 2 A. PawnChess
- Codeforces 592A. PawnChess
- Codeforces 592A PawnChess 【水题】
- Codeforces Round #328 (Div. 2)(A B C D)
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #174 (Div. 2) Problem A
- Codeforces Round #173 (Div. 2) A.Bit++
- 在公司3个月的一些积累
- Collections集合工具类
- 可计算代数数论(2012-12-09 20:56、2013-03-23 21:39、2013-06-23 20:27、2013-06-23 20:32、2014-05-16 17:49)
- Poj2388_Who's in the Middle
- Oracle的主要进程简要
- Codeforces Round #328 (Div. 2)A. PawnChess
- Why Floating-Point Numbers May Lose Precision
- 解决cocos2dx CCArmature动画在部分型号的安卓手机上播放不正常的问题
- 关于CCArmature加载时因为plist中含有相同名称的图片导致碰撞框被冲掉的解决办法。
- ubuntu 改时区
- 黑马程序员视频加源码
- eclipse for android安装过程
- Codeforces Round #328 (Div. 2)B. The Monster and the Squirrel
- Day2(11.1):(2)选择合适的数据类型