Codeforces Round #328 (Div. 2)_A. PawnChess
1 second
256 megabytes
standard input
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.
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先走 */ #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring> using namespace std; int main() {
char a[8][8];
memset(a, 0, sizeof(a));
for (int i = 0; i<8; i++) {
for (int j = 0; j<8; j++) {
cin>> a[i][j];
}
}
int num1 = 100, num2 = 100;
int flag = 1;
for (int i = 0; i<8; i++) {
for (int j = 0; j<8; j++) {
flag = 1;
if (a[i][j] == 'W') {
for (int k = i-1; k>=0; k--) {
if (a[k][j] != '.')
flag = 0;
}
if (flag == 1) {
if (i < num1)
num1 = i;
}
}
flag = 1;
if (a[i][j] == 'B') {
for (int k = i+1; k<8; k++) {
if (a[k][j] != '.')
flag = 0;
}
if (flag == 1) {
if ((8-i-1) < num2)
num2 = 8-i-1;
}
}
}
}
if (num1 <= num2) //步数相等则A胜
cout << "A"<< endl;
else
cout << "B"<< endl; return 0;
}
Codeforces Round #328 (Div. 2)_A. PawnChess的更多相关文章
- Codeforces Round #328 (Div. 2) A. PawnChess 暴力
A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...
- Codeforces Round #328 (Div. 2)
这场CF,准备充足,回寝室洗了澡,睡了一觉,可结果... 水 A - PawnChess 第一次忘记判断相等时A先走算A赢,hack掉.后来才知道自己的代码写错了(摔 for (int i=1; ...
- Codeforces Round #328 (Div. 2) D. Super M
题目链接: http://codeforces.com/contest/592/problem/D 题意: 给你一颗树,树上有一些必须访问的节点,你可以任选一个起点,依次访问所有的必须访问的节点,使总 ...
- Codeforces Round #328 (Div. 2) D. Super M 虚树直径
D. Super M Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/D ...
- Codeforces Round #328 (Div. 2) C. The Big Race 数学.lcm
C. The Big Race Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/probl ...
- Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学
B. The Monster and the Squirrel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...
- Codeforces Round #328 (Div. 2) A
A. PawnChess time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #347 (Div.2)_A. Complicated GCD
题目链接:http://codeforces.com/contest/664/problem/A A. Complicated GCD time limit per test 1 second mem ...
- Codeforces Round #331 (Div. 2) _A. Wilbur and Swimming Pool
A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes input s ...
随机推荐
- Fiori缓存与它的清除
最近在修改已有的Fiori应用,遇到了缓存上的一点问题,导致对Fiori应用的代码修改不能在前端页面生效.现将自己查到的一篇好资料翻译过来,以供参考.以下为正文. 2017.12.19更新:最近又遇到 ...
- 【Zookeeper】源码分析之服务器(五)之ObserverZooKeeperServer
一.前言 前面分析了FollowerZooKeeperServer,接着分析ObserverZooKeeperServer. 二.ObserverZooKeeperServer源码分析 2.1 类的继 ...
- 关于使用Log4Net将日志插入oracle数据库中
1.关于配置文件. <?xml version="1.0" encoding="utf-8" ?> <configuration> &l ...
- python科学计算_scipy_常数与优化
scipy在numpy的基础上提供了众多的数学.科学以及工程计算中常用的模块:是强大的数值计算库: 1. 常数和特殊函数 scipy的constants模块包含了众多的物理常数: import sci ...
- 配置apache的文件访问路径
本例中,我们让apache访问"F:/testObject/php"路径: 一.修改http.conf文件配置 访问路径:"apache/conf/httpd.conf& ...
- C# log4net 的配置
项目的日志组件是必备可少的,任何项目中都需要.这样既方便前期的开发测试也方便项目后期的项目维护.C#项目的一个不错的日志组件是log4net,下面我就把桌面应用程序.控制台程序.网站中log4net的 ...
- 【Python3之字符编码】
一.字符集和字符编码 1.定义 计算机中储存的信息都是用二进制数表示的,而我们在屏幕上看到的英文.汉字等字符是二进制数转换之后的结果.通俗的说,按照何种规则将字符存储在计算机中,如'a'用什么表示,称 ...
- 那些年原生js实现的楼层跳转
最近做一个需求~~楼层跳转(京东.淘宝侧边导航),由于现在项目都用框架,所以 jquery是不能再用了,只好自己原生写一个,其实实现起来很简单,无非就是获取到每个楼层距离文档顶部的距离,然后通过控制滚 ...
- http协议【转】
HTTP协议详解 当今web程序的开发技术真是百家争鸣,ASP.NET, PHP, JSP,Perl, AJAX 等等. 无论Web技术在未来如何发展,理解Web程序之间通信的基本协议相当重要, 因为 ...
- Java框架之Hibernate(四)
本文主要介绍: 1 悲观锁和乐观锁 2 使用版本号控制并发访问 3 flush方法和批量更新的问题 4 DetachedCriteria 5 N + 1 次查询 6 使用sql进行查询 7 注解方式 ...