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 暴力的更多相关文章

  1. 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 ...

  2. Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力

    B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...

  3. 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 ...

  4. Codeforces Round #328 (Div. 2) A

    A. PawnChess time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  5. Codeforces Round #328 (Div. 2)

    这场CF,准备充足,回寝室洗了澡,睡了一觉,可结果...   水 A - PawnChess 第一次忘记判断相等时A先走算A赢,hack掉.后来才知道自己的代码写错了(摔 for (int i=1; ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #328 (Div. 2) D. Super M

    题目链接: http://codeforces.com/contest/592/problem/D 题意: 给你一颗树,树上有一些必须访问的节点,你可以任选一个起点,依次访问所有的必须访问的节点,使总 ...

  9. 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 ...

随机推荐

  1. Delphi EVariantTypeCastError错误的解决方法

    在执行程序的时候总是提示: ---------------------------Debugger Exception Notification---------------------------P ...

  2. GreenDao官方文档翻译(上)

    笔记摘要: 上一篇博客简单介绍了SQLite和GreenDao的比较,后来说要详细介绍下GreenDao的使用,这里就贴出本人自己根据官网的文档进行翻译的文章,这里将所有的文档分成上下两部分翻译,只为 ...

  3. [转] c#中 多线程访问winform控件

    原文 c#中多线程访问winform控件的若干问题小结 我们在做winform应用的时候,大部分情况下都会碰到使用多线程控制界面上控件信息的问题.然而我们并不能用传统方法来解决这个问题,下面我将详细的 ...

  4. 给Webkit内核的浏览器控件增加互交功能

    转载请说明出处,谢谢~~ 昨天封装了基于webkit的wke浏览器内核,做成了duilib的浏览器控件,实现了浏览功能,但是单单的浏览功能还不满足需求,在我的仿酷狗项目中乐库的功能需要与浏览器互交. ...

  5. Eclipse编辑java文件报Unhandled event loop exception错误的解决办法

    原因:电脑中安装了杀毒软件,卸掉或者关掉就可以了.我的是直接退出,错误就不产生了.

  6. 采集网页数据---Using Java

    http://www.cnblogs.com/longwu/archive/2011/12/24/2300110.html 1).学习网页数据采集,首先必不可少的是学习java的正则表达式(Regex ...

  7. codevs3044 线段树+扫描线

    3044 矩形面积求并 http://hzwer.com/879.html 扫描线 // #pragma comment(linker, "/STACK:1024000000,1024000 ...

  8. 解读MMS(Microsoft Media Server)协议

    下面是一次截取的MMS协议开始帧 部分(十六进制): 01000000cefa0bb0c00000004d4d5320 18000000000000000000000000000000 1600000 ...

  9. Ineligible Devices 不被识别的设备

    设备不可用,出现Ineligible Devices,如下图: 此错误因为 Xcode的Deployment Target 大于设备的,选择和设备一样活着低于设备的.如下图:

  10. 第二百九十九天 how can I 坚持

    不是傻,就是因为人太好了,我宁愿相信是我人太好了,好吧,我就是对人都挺好,这是病吗. 昨天一起吃的饭一起AA了,挺好,这种事就得AA,玩的挺happy. 还有.感觉自己好傻,老是遇事焦虑,以后试着改变 ...