CF 328 Div 2 A. pawnchess

Source: Internet
Author: User
Tags first row time limit

Http://codeforces.com/contest/592/problem/A

A. pawnchess time limit per test 1 second memory limit per test 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 was played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns is placed on the board. The number of black pawns placed is isn't necessarily equal to the number of white pawns placed.

Lets Enumerate rows and columns with integers from 1 to 8. Rows is numbered from the top to the bottom, while columns is numbered from. Now we denote as (R, c) the cell located at the row R and at the column C.

There is always players A and B playing the game. Player A plays with the white pawns, while the player B plays with black ones. The goal of player A is to put any of the pawns to the row 1, and while player B tries to put any of the of his pawns to the row 8. As soon as any of the players completes he goal the game finishes immediately and the succeeded player is declared a Winn Er.

Player A moves first and then they alternate turns. On he 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 was possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there would always be at least one move available for any of the players.

Moving upward means that the pawn located in (R, c) would go to the cell (R-1, c), while moving down means the pawn Locat Ed in (R, c) would go to the cell (R + 1, c). Again, the corresponding cell must is empty, i.e. not occupied by any and pawn of any color.

Given the initial disposition of the Board, determine who wins the game if both players play optimally. Note that there would always is a winner due to the restriction so for any game scenario both players would have some move S available. Input

The input consists of the board description given in eight lines, each line contains eight characters. Character ' B ' is used-denote a black pawn, and Character ' W ' represents a white pawn. Empty cell is marked with '. '.

It's guaranteed that there is not being 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 would claim the victory. Again, it ' s guaranteed that there would 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
Main topic:

Player A Use w pawn,player b use b pawn, b pawn want go to row 8,and W pawn want go to row 1,but if tow pawn in on column, and B is high than w,they can ' t

Move, A Frist move, every time, they can only move one cell,who frist get the destination, who is Winer, ouput Winer;

Me code::

#include <iostream> #include <algorithm> #include <string.h> using namespace std;
Char map[10][10];
    int main () {int w=100,b=-9;
    for (int i=0;i<8;i++) cin>>map[i];
              for (int i=0;i<8;i++) {for (int j=0;j<8;j++) {if (map[i][j]== ' W ') {
              int flag=0;
              for (int k=i-1;k>=0;k--) {if (map[k][j]== ' B ') flag=1;
              } if (flag==0&&i<w) {w=i; }}}} for (int i=7;i>=0;i--) {for (int j=0;j<8;j++) {if (
                map[i][j]== ' B ') {int ff=0;
                for (int k=i+1;k<8;k++) {if (map[k][j]== ' W ') ff=1;
            } if (ff==0&&i>b) b=i;
  }
        }  } b=8-b-1;
    cout<<w<< "" <<b<<endl;
    if (w<=b) cout<< "A" <<endl;

    else cout<< "B" <<endl;
return 0;
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.