zoukankan      html  css  js  c++  java
  • HDU 5546 Ancient Go DFS

    Ancient Go

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
    Total Submission(s): 1732    Accepted Submission(s): 552


    Problem 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 8×8 cell board, the chess can be put on the intersection of the board lines, so there are 9×9 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, T(1T100)T 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. x represents a cell with black chess which owned by Yu Zhou. o represents a cell with white chess which owned by Su Lu.
     
    Output
    For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y 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.
     
    Source
     
    Recommend
    wange2014   |   We have carefully selected several similar problems for you:  5981 5980 5979 5978 5977 
     
     
    回头看一下好久没写题解了  省赛之后太堕落了 今天开始要重新努力刷题了不然很快就变成一条咸鱼了
     
    这条题就是围棋的规则 问能不能在给出的情况下用一步来干掉至少一个棋子
    我们可以转换为求白棋有多少个气孔 大于等于2个的话就不能被干掉 这样的话我们直接遍历棋盘里面的白棋 然后对他们进行dfs就可以了 
     
     
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <iomanip>
    #include <math.h>
    #include <map>
    using namespace std;
    #define FIN     freopen("input.txt","r",stdin);
    #define FOUT    freopen("output.txt","w",stdout);
    #define INF     0x3f3f3f3f
    #define INFLL   0x3f3f3f3f3f3f3f
    #define lson    l,m,rt<<1
    #define rson    m+1,r,rt<<1|1
    typedef long long LL;
    typedef pair<int, int> PII;
    
    char chess[15][15];
    int vis[15][15];
    int flag, num;
    //xo
    
    bool check(int x, int y) {
        return x >= 0 && x <= 8 && y >= 0 && y <= 8 && chess[x][y] != 'x' && vis[x][y] == 0;
    }
    
    void llss(int x, int y) {
        if(num >= 2) return ;
        if(check(x, y)) {
            vis[x][y] = 1;
            if(chess[x][y] == 'o') {
                llss(x + 1, y);
                llss(x - 1, y);
                llss(x, y + 1);
                llss(x, y - 1);
            } else {
                num++;
            }
        } else return ;
    
    }
    
    int main()
    {
        //FIN
        int T;
        int cas = 1;
        scanf("%d", &T);
        while(T--) {
            flag = 0;
            for(int i = 0; i < 9; i++) scanf("%s", chess[i]);
            for(int i = 0; i < 9; i++) {
                for(int j = 0; j < 9; j++) {
                    memset(vis, 0, sizeof(vis));
                    num = 0;
                    if(chess[i][j] == 'o' && flag == 0)  llss(i, j);
                    if(num == 1) {
                        flag = 1;
                        break;
                    }
                }
            }
            if(flag) printf("Case #%d: Can kill in one move!!!
    ", cas++);
            else printf("Case #%d: Can not kill in one move!!!
    ", cas++);
    
        }
    
    }
    

      

     
  • 相关阅读:
    第十三周学习进度条
    冲刺第四天
    第二天冲刺
    第三天冲刺
    第一天冲刺
    课下作业
    第十二周学习进度条
    课下作业
    webp与png、jpg相互转换
    Node疑难解决
  • 原文地址:https://www.cnblogs.com/Hyouka/p/6041290.html
Copyright © 2011-2022 走看看