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

本文深入探讨了游戏开发领域的核心技术,包括游戏引擎、图形渲染、3D空间视频等关键概念及应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. PawnChess
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

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 test(s)
Input
........
........
.B....B.
....W...
........
..W.....
........
........
Output
A
Input
..B.....
..W.....
......B.
........
.....W..
......B.
........
........
Output
B
Note

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.



题意:在一个8*8的棋盘中,有白子和蓝子,蓝子任何一个走到第8行为胜利,白子任何一个走到第一行为胜利,判断谁胜利


思路:8*8,直接暴力就行了,计算当前行和目标行的距离


ac代码:

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#define MAXN 100100
#define MOD 1000000007
#define LL long long
#define INF 0xfffffff
using namespace std;
char map[10][10]; 
int main()
{
	int i,j,k;
	while(scanf("%s",map[0])!=EOF)
	{
		for(i=1;i<8;i++)
		scanf("%s",map[i]);
		int num1=INF;
		int num2=INF;
		int flag;
		for(i=0;i<8;i++)
		{
			for(j=0;j<8;j++)
			{
				if(map[i][j]=='B')
				{
					flag=0;
					for(k=i+1;k<8;k++)
					if(map[k][j]=='B'||map[k][j]=='W')
					{
						flag=1;
						break;
					}
					if(flag)
					continue;
					else
					num2=min(num2,7-i);
				}
				else if(map[i][j]=='W')
				{
					flag=0;
					for(k=i-1;k>=0;k--)
					if(map[k][j]=='B'||map[k][j]=='w')
					{
						flag=1;
						break;
					}
					if(flag)
					continue;
					else
					num1=min(num1,i);
				}
			}
		}
		if(num1>num2)
		printf("B\n");
		else
		printf("A\n");
	}
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值