Codeforces Round #328 (Div. 2) A. PawnChess 暴力
A. PawnChess
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/592/problem/A
Description
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 Input
........
.B....B.
....W...
........
..W.....
........
........
Sample Output
A
HINT
题意
有一个8*8的棋盘,A先走,B后走,每次A可以操纵一个W棋子向上走
B可以操作一个棋子向下走,如果路上被挡住了,那就不能走了
然后问你,谁会第一个走到上下边界位置
题解:
暴力for就好了
这里面有个TRICK,当大家ans都是一样的话,那么输出A就行了
代码
#include<iostream>
#include<stdio.h>
using namespace std; string s[];
int vis[][];
int main()
{
int n = ; for(int i=;i<n;i++)
cin>>s[i]; for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(s[i][j]!='.')
vis[i][j]=;
}
} int ans1 = ;
int ans2 = ; for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
if(s[i][j]=='W')
{
int flag = ;
int step = ;
for(int k=i-;k>=;k--)
{
if(vis[k][j])
flag = ;
step++;
}
if(flag==)
ans1 = min(ans1,step);
}
if(s[i][j]=='B')
{
int flag = ;
int step = ;
for(int k=i+;k<;k++)
{
if(vis[k][j])
flag = ;
step++;
}
if(flag==)
ans2 = min(ans2,step);
}
}
}
if(ans1<=ans2)
puts("A");
else
puts("B");
}
Codeforces Round #328 (Div. 2) A. PawnChess 暴力的更多相关文章
- Codeforces Round #328 (Div. 2)_A. PawnChess
A. PawnChess time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力
B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...
- Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)
A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...
- 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 #328 (Div. 2)
这场CF,准备充足,回寝室洗了澡,睡了一觉,可结果... 水 A - PawnChess 第一次忘记判断相等时A先走算A赢,hack掉.后来才知道自己的代码写错了(摔 for (int i=1; ...
- Codeforces Round #369 (Div. 2) A B 暴力 模拟
A. Bus to Udayland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #188 (Div. 1) B. Ants 暴力
B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Des ...
- Codeforces Round #328 (Div. 2) D. Super M
题目链接: http://codeforces.com/contest/592/problem/D 题意: 给你一颗树,树上有一些必须访问的节点,你可以任选一个起点,依次访问所有的必须访问的节点,使总 ...
- Codeforces Round #329 (Div. 2) A. 2Char 暴力
A. 2Char Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/A De ...
随机推荐
- 【树状数组(二叉索引树)】轻院热身—candy、NYOJ-116士兵杀敌(二)
[概念] 转载连接:树状数组 讲的挺好. 这两题非常的相似,查询区间的累加和.更新结点.Add(x,d) 与 Query(L,R) 的操作 [题目链接:candy] 唉,也是现在才发现这题用了这个知识 ...
- addView的误区
如果在代码中动态使用addView(v),那么v里头所有在xml里设置好的layout_xxx全部失效!
- Fitnesse+RestFixture:Web服务回归测试利器
RestFixture是Fitness的一个测试REST服务的插件,用于调用标准的http GET/POST等请求方法,并可以用XPath语法和Javascript语法检验http响应.本文介绍安装运 ...
- STM32F407 外扩SRAM
字节控制功能.支持高/低字节控制. 看看实现 IS62WV51216 的访问,需要对 FSMC进行哪些配置. 这里就做一个概括性的讲解.步骤如下: 1)使能 FSMC 时钟,并配置 FSMC 相关的 ...
- [Hive优化] 之 MapJoin
根据mapjoin的计算原理,MAPJION会把小表全部读入内存中,在map阶段直接拿另外一个表的数据和内存中表数据做匹配.这种情况下即使笛卡尔积也不会对任务运行速度造成太大的效率影响. mapjoi ...
- 内核源码分析之软中断(基于3.16-rc4)
1.和软中断相关的数据结构: softing_vec数组(kernel/softirq.c) static struct softirq_action softirq_vec[NR_SOFTIRQS] ...
- A题进行时--浙大PAT 1011-1020
#include<stdio.h> #include<string.h> int main(){ ]; ]; ]; ]; ]; int i; float sum; memset ...
- Mac vim iterm2配色方案
转自:http://www.vpsee.com/2013/09/use-the-solarized-color-theme-on-mac-os-x-terminal/ 相信长期浸泡在终端和代码的小伙伴 ...
- leetcode@ [343] Integer Break (Math & Dynamic Programming)
https://leetcode.com/problems/integer-break/ Given a positive integer n, break it into the sum of at ...
- socket.io的抽象实现:engine.io
engine.io是一个socket.io的抽象实现,作为socket.io的服务器和浏览器之间交换的数据的传输层.它不会取代Socket.IO,它只是抽象出固有的复杂性,支持多种浏览器,设备和网络的 ...