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 ...
随机推荐
- Linux 平台下 YUM 源配置 手册
Redhat/Centos 系的Linux 平台,推荐使用YUM 来安装相关依赖包. 安装方式有两种,一种是使用本地的YUM,一种使用在线的YUM. 1 在线YUM 源 如果操作系统能 ...
- 【html】页面制作规范文档
每天都在写html/css/js代码,总结的一些页面制作的规范 文件命名规范 1) 文件目录.文件名称统一用小写的英文字母.数字.下划线组合,文件名要与表现的内容相近,不到万不得已不要以拼音作为名称, ...
- 【已解决】Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8
[问题] 折腾: [已解决]Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8 过程中,增大对应AVD的内存为2G后,结果无法启 ...
- 也说Autofac在MVC的简单实践:破解在Controller构造函数中的实例化 - winhu
相信大家对Autofac并不陌生,很多人都在使用.本文只是介绍一下本人在使用时的一点想法总结. 在使用一个框架时,肯定要去它的官网查阅一下.autofac的官网给出了一些经典的使用案例.如注册容器: ...
- 【转】http-equiv的含义
http-equiv顾名思义,相当于http的文件头作用,它可以向浏览器传回一些有用的信息,以帮助正确和精确地显示网页内容,与之对应的属性值为content,content中的内容其实就是各个参数的变 ...
- 为SQL表添加全文索引范例
--范例: --为HR_Job中的JobTitle,JobDes创建全文索引 execute sp_fulltext_catalog 'boli188', 'create' --创建全文目录,boli ...
- [转] AE之分级颜色专题图渲染
原文 AE之分级颜色专题图渲染 参考代码1 private void 分级渲染ToolStripMenuItem_Click(object sender, EventArgs e) { //值分级 I ...
- 查看linux服务器中的apache是否安装以及安装路径
1.可以通过 apachectl -v 查看apache是否安装,如果安装了的话会显示版本号: 2.如果通过rpm包安装的话可以用 rpm -q httpd 查看,如果安装的的话会显示包的名称
- bzoj 2393 Cirno的完美算数教室(容斥原理+搜索)
[题意] 定义C数为只包含数字2和9的数,求[L,R]内能被C数整除的个数. [思路] Dfs预处理出C数,并去除其中倍数的情况. Dfs搜索出现情况,奇数加,偶数减,当数值大于R时剪枝. [代码] ...
- 瞬间从IT屌丝变大神——HTML规范
HTML规范包含以下内容: DTD统一用<!DOCTYPE HTML PUBLIC "_//W3C//DTD XHTML 1.0 Transitional//EN"" ...