码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #328 (Div. 2) A

时间:2016-07-20 22:51:16      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:

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.

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

 根据题意,我们是寻找W B到边界谁最短,自然就是遍历一次,找到以后,寻找他们在路上有没有拦路的,没有就记录最短~题目说一定会存在路径,不会出现堵死的情况~

#include<bits/stdc++.h>
using namespace std;
int main()
{
    char c[1000][1000];
    int n=1000,m=1000;


    for(int i=1;i<=8;i++)
    {
        for(int j=1;j<=8;j++)
        {
            cin>>c[i][j];
        }
    }
    for(int i=1;i<=8;i++)
    {
        for(int j=1;j<=8;j++)
        {
            if(c[i][j]==‘W‘)
            {
                int flag1=0;
                for(int k=i-1;k>=1;k--)
                {
                //    cout<<c[k][j]<<"C"<<endl;
                    if(c[k][j]!=‘.‘)
                    {
                        flag1=1;
                        break;
                    }
                }
              //  cout<<flag1<<"A"<<endl;
              //  cout<<i<<"B"<<endl;
                if(flag1==0)
                {
                    n=min(n,i-1);
                }
            }
            if(c[i][j]==‘B‘)
            {
                int flag2=0;
                for(int k=i+1;k<=8;k++)
                {
                    if(c[k][j]!=‘.‘)
                    {
                        flag2=1;
                        break;
                    }
                }
                if(flag2==0)
                {
                m=min(m,8-i);
                }
            }
        }
    }
   // cout<<n<<endl;
   // cout<<m<<endl;
    if(n<=m)
    {
        puts("A");
    }
    else
    {
        puts("B");
    }
    return 0;
}

  

Codeforces Round #328 (Div. 2) A

标签:

原文地址:http://www.cnblogs.com/yinghualuowu/p/5689795.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!