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 ...
随机推荐
- 【NOIP模拟】cut
Description F大爷热爱切树.今天他找到一棵黑白树,不到两秒钟,F大爷就把这棵树切掉了.已知原先树上共n个点,每个点都是黑点或者白点,F大爷切去若干条边后,分成的若干个连通子树中每块恰有一个 ...
- node学习心得
此次学习主要使用的是基于nodejs平台的web应用开发框架. 一.express的工程结构 1.bin/www:express的执行入口,存放可执行文件: 2.node_modules:存放pack ...
- powerdesigner的使用
前言 做过建模和设计的人都知道,powerdesigner是个强大实用的工具:采用模型驱动方法,将业务与IT结合起来,可帮助部署有效的企业体系架构,并为研发生命周期管理提供强大的分析与设计技术.本文档 ...
- thinkinginjava学习笔记01_导论
初学java,希望旅途愉快 :) 类型决定对象的接口,(有人认为类是类型的特定实现),接口确定对象所能发出的请求(消息),满足请求的代码和隐藏的数据一起构成实现: 对象设计时,应该很好地完成一项任务 ...
- golang 栈操作
Monk's Love for Food Our monk loves food. Hence,he took up position of a manager at Sagar,a restau ...
- 【转载】MySQL事务以及SELECT ... FOR UPDATE的使用
MySQL中的事务,默认是自动提交的,即autocommit = 1: 但是这样的话,在某些情形中就会出现问题:比如: 如果你想一次性插入了1000条数据,mysql会commit1000次的, 如果 ...
- 如何在开发时部署和运行前后端分离的JavaWeb项目
在开发中大型的JavaEE项目时,前后端分离的框架逐渐成为业界的主流,传统的单机部署前后端在同一个项目中的工程项目越来越少.这类JavaWeb项目的后端通常都采用微服务的架构,后端会被分解为诸多个小项 ...
- 【Java框架型项目从入门到装逼】第六节 - 用ajax请求后台数据
这一节我们来说一下如何用ajax提交请求? 我们先不讲ajax的原理,还是先以实战为主,看一下这个东西到底怎么用的? form表单: <!-- 采用post表单提交 --> <for ...
- 未知宽高图片水平垂直居中在div
<BODY> <div class="box"> <span class="car"></span> <i ...
- k8s 重要概念 - 每天5分钟玩转 Docker 容器技术(117)
在实践之前,必须先学习 Kubernetes 的几个重要概念,它们是组成 Kubernetes 集群的基石. Cluster Cluster 是计算.存储和网络资源的集合,Kubernetes 利用这 ...