博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #328 (Div. 2) A. PawnChess 暴力
阅读量:6941 次
发布时间:2019-06-27

本文共 3582 字,大约阅读时间需要 11 分钟。

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
#include
using namespace std;string s[10];int vis[10][10];int main(){ int n = 8; for(int i=0;i
>s[i]; for(int i=0;i
=0;k--) { if(vis[k][j]) flag = 1; step++; } if(flag==0) ans1 = min(ans1,step); } if(s[i][j]=='B') { int flag = 0; int step = 0; for(int k=i+1;k<8;k++) { if(vis[k][j]) flag = 1; step++; } if(flag==0) ans2 = min(ans2,step); } } } if(ans1<=ans2) puts("A"); else puts("B");}

 

转载地址:http://bvgjl.baihongyu.com/

你可能感兴趣的文章
统计网站PV和UV
查看>>
高度已知,三栏布局,左右宽度300,中间自适应
查看>>
vuex use notes
查看>>
iOS关于编译那些事儿
查看>>
Stream(流)的基本使用
查看>>
观察者模式
查看>>
序算法时间复杂度、空间复杂度分享
查看>>
初探16.3+React升级后的生命周期
查看>>
ES6新特性总结
查看>>
文件I/O
查看>>
es6 class
查看>>
spring cloud微服务分布式云架构(三)-服务消费者(Feign)
查看>>
Vue之computed(计算属性)详解get()、set()
查看>>
Java 集合系列05之 LinkedList详细介绍(源码解析)和使用示例
查看>>
GMQ交易平台重塑数字资产交易格局
查看>>
Python爬虫入门教程 22-100 CSDN学院课程数据抓取
查看>>
Parasoft C / C ++Test10.4.1发布!完全支持SEI CERT C ++安全编码标准!
查看>>
Markdown 简明语法
查看>>
区块链100讲:零知识证明算法之zkSNARKs
查看>>
SpringBoot2系列教程(一)简介及HelloWorld项目
查看>>