• hdu---5546---Ancient Go


    题目链接:

    http://acm.hdu.edu.cn/showproblem.php?pid=5546

    Description

    Yu Zhou likes to play Go with Su Lu. From the historical research, we found that there are much difference on the rules between ancient go and modern go. 
    Here is the rules for ancient go they were playing: 
    The game is played on a  cell board, the chess can be put on the intersection of the board lines, so there are  different positions to put the chess.  Yu Zhou always takes the black and Su Lu the white. They put the chess onto the game board alternately.  The chess of the same color makes connected components(connected by the board lines), for each of the components, if it's not connected with any of the empty cells, this component dies and will be removed from the game board.  When one of the player makes his move, check the opponent's components first. After removing the dead opponent's components, check with the player's components and remove the dead components.  One day, Yu Zhou was playing ancient go with Su Lu at home. It's Yu Zhou's move now. But they had to go for an emergency military action. Little Qiao looked at the game board and would like to know whether Yu Zhou has a move to kill at least one of Su Lu's chess.

    Input

    The first line of the input gives the number of test cases, .  test cases follow. Test cases are separated by an empty line. Each test case consist of 9 lines represent the game board. Each line consists of 9 characters. Each character represents a cell on the game board.  represents an empty cell.  represents a cell with black chess which owned by Yu Zhou.  represents a cell with white chess which owned by Su Lu.

    Output

    For each test case, output one line containing Case #x: y, where  is the test case number (starting from 1) and  is Can kill in one move!!! if Yu Zhou has a move to kill at least one of Su Lu's components. Can not kill in one move!!! otherwise.

    Sample Input

    2
    
    .......xo
    .........
    .........
    ..x......
    .xox....x
    .o.o...xo
    ..o......
    .....xxxo
    ....xooo.
    
    ......ox.
    .......o.
    ...o.....
    ..o.o....
    ...o.....
    .........
    .......o.
    ...x.....
    ........o

    Sample Output

    Case #1: Can kill in one move!!!
    Case #2: Can not kill in one move!!!
    
            
     

    Hint

     
    In the first test case, Yu Zhou has 4 different ways to kill Su Lu's component. In the second test case, there is no way to kill Su Lu's component.

    真是要疯了,一道题并不难的题,由于题意一直读不懂,愣是弄了快3个小时才OK

    Mean:

    我方棋子是'x',敌方是'o'。现在轮到我方落子,问我方能不能在下一回合吃掉对方的至少一个棋子。

    吃掉的规则是:对方被围的棋子在下一回合时已经找不到为' . '的位置,就是我下一个棋子把‘o’包围了。

    范围:棋盘大小9*9。

    Analse:

    枚举每一个'.',使其变成'x',在这一点周围四个点为方向进行DFS,遇到'x'返回,如果存在一个DFS过程中没发现'.'即存在。

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <cmath>
    #include<vector>
    #include<queue>
    #include<algorithm>
    
    using namespace std;
    typedef long long LL;
    
    const int maxn=1000005;
    const int INF=0x3f3f3f3f;
    
    char maps[10][10];
    int vis[10][10];
    int dir[4][2]= {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    int f;
    
    void DFS(int x, int y)
    {
        vis[x][y]=1;
    
        if(maps[x][y]=='.')
        {
            f=1;
            return ;
        }
    
        if(maps[x][y]=='x')return ;
    
        for(int i=0; i<4; i++)
        {
            int nx=x+dir[i][0];
            int ny=y+dir[i][1];
    
            if(nx>=0&&nx<9&&ny>=0&&ny<9&&!vis[nx][ny])
                DFS(nx, ny);
        }
    }
    int solve()
    {
        for(int i=0; i<9; i++)
        {
            for(int j=0; j<9; j++)
            {
                if(maps[i][j]=='.')///枚举每一个'.'
                {
                    maps[i][j]='x';///将其变成黑棋
                    for(int k=0; k<4; k++)
                    {
                        int nx=i+dir[k][0];
                        int ny=j+dir[k][1];
    
                        if(nx>=0&&nx<9&&ny>=0&&ny<9&&maps[nx][ny]=='o')///寻找'.'周围合法的白棋
                        {
                            memset(vis, 0, sizeof(vis));
                            f=0;
                            DFS(nx, ny);///判断白棋是否能够被我方黑棋包围
                            if(!f)
                                return 1;
                        }
                    }
                    maps[i][j]='.';///如果其周围没有白棋或者黑棋包围白棋不成功,还要将其还原为'.'
                }
            }
        }
        return 0;
    }
    int main()
    {
        int T, cas=1;
        scanf("%d", &T);
    
        while(T--)
        {
            for(int i=0; i<9; i++)
                scanf("%s", maps[i]);
    
            int ans=solve();
            if(ans)printf("Case #%d: Can kill in one move!!!
    ", cas++);
            else
                printf("Case #%d: Can not kill in one move!!!
    ", cas++);
        }
        return 0;
    }
  • 相关阅读:
    【华为云技术分享】区块链与数据库如何结合?
    【华为云技术分享】跟繁琐的命令行说拜拜!Gerapy分布式爬虫管理框架来袭!
    gin casbin xorm vue-admin权限认证。
    golang优秀库及介绍
    网上的element-ui-admin运行
    golang时区处理
    Let's Encrypt apache的配置
    wireshark分析自己向自己请求服务
    XORM的几个常用数据处理
    golang处理json
  • 原文地址:https://www.cnblogs.com/w-y-1/p/5773766.html
Copyright © 2020-2023  润新知