zoukankan      html  css  js  c++  java
  • Codeforces Round #328 (Div. 2)_A. PawnChess

    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.

    /*题目大意:A与B下棋,A只能向上走、B只能向下,谁先到达最顶端或最低端谁胜
     *         这里注意的是A先走 
    
    */
    
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    
    using namespace std;
    
    int main() {
        char a[8][8];
        memset(a, 0, sizeof(a));
        for (int i = 0; i<8; i++) {
            for (int j = 0; j<8; j++) {
                cin>> a[i][j];
            }
        }
        int num1 = 100, num2 = 100;
        int flag = 1;
        for (int i = 0; i<8; i++) {
            for (int j = 0; j<8; j++) {
                flag = 1;
                if (a[i][j] == 'W') {
                    for (int k = i-1; k>=0; k--) {
                        if (a[k][j] != '.')
                            flag = 0;
                    }
                    if (flag == 1) {
                        if (i < num1)
                            num1 = i;
                    }
                }
                flag = 1;
                if (a[i][j] == 'B') {
                    for (int k = i+1; k<8; k++) {
                        if (a[k][j] != '.')
                            flag = 0;
                    }
                    if (flag == 1) {
                        if ((8-i-1) < num2)
                            num2 = 8-i-1;
                    }
                }
            }
        }
        if (num1 <= num2)							//步数相等则A胜 
            cout << "A"<< endl;
        else
            cout << "B"<< endl;
    
        return 0;
    }


  • 相关阅读:
    angular6跨域问题proxy.conf.json
    angular2 防止刷新页面 参数丢失
    自定义修改table样式 scoped会影响
    angular ngfor和ngif指令共用
    yum 是轮船发动机,brew 是汽车发动机,不能混用。
    Vue watch 监听 computed
    vue 路由跳转,参数消失问题
    vue 使用:class切换高亮 点击路由跳转 上个组件的点击事件保存的参数 在下一次重复进入这个组件的时候 默认值都已经还原了 得通过路由跳转的时候 把上个组件的状态通过路由保存下来 通过下一次进入这个组件的时候 获取路由 渲染当前页面的:class 进行高亮
    函数防抖 函数节流
    vue router-view router-link RouterView【命令视图】和RouterLink【命令路线】本身是两个组件。 命名路由
  • 原文地址:https://www.cnblogs.com/Tovi/p/6194835.html
Copyright © 2011-2022 走看看