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

    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<iostream>
    #include<stdio.h>
    using namespace std;
    
    string s[10];
    int vis[10][10];
    int main()
    {
        int n = 8;
    
        for(int i=0;i<n;i++)
            cin>>s[i];
    
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(s[i][j]!='.')
                    vis[i][j]=1;
            }
        }
    
        int ans1 = 999;
        int ans2 = 999;
    
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(s[i][j]=='W')
                {
                    int flag = 0;
                    int step = 0;
                    for(int k=i-1;k>=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");
    }
  • 相关阅读:
    visual studio 2015 Opencv 3.4.0配置
    读漫谈架构博文有感
    代码阅读方法与实践阅读笔记06
    代码阅读方法与实践阅读笔记05
    apache https 伪静态
    今天网站后台登录页面需要生成一个二维码,然后在手机app上扫描这个二维码,实现网站登录的效果及其解决方案如下
    架设lamp服务器后,发现未按照 Apache xsendfile模块,
    linux下bom头导致的php调用php接口 返回的json字符串 无法转成 数组,即json字符串无法解码的问题
    什么是OAuth授权?
    以application/json 方式提交 然后用在php中读取原始数据流的方式获取 在json_encode
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4927666.html
Copyright © 2011-2022 走看看