• 2015南阳CCPC G


    G - Ancient Go

    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(1≤T≤100). 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!!!


    题意:下围棋规则,给你一个9*9的棋盘:上面有圈叉,现在轮到你下叉子,判断是否能够杀死至少一枚圈
    题解;直接枚举所有下子的情况,判断是否叉围住了至少一个圈。……——……
    ///1085422276
    #include<bits/stdc++.h>
    using namespace std ;
    typedef long long ll;
    #define mem(a) memset(a,0,sizeof(a))
    #define meminf(a) memset(a,127,sizeof(a))
    #define FOR(i,a,b) for( int i=a;i<=b;i++)
    #define inf 100000
    inline ll read()
    {
        ll x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9')
        {
            if(ch=='-')f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9')
        {
            x=x*10+ch-'0';
            ch=getchar();
        }
        return x*f;
    }
    //****************************************
    #define maxn 11
    int ss[4][2]={-1,0,0,-1,1,0,0,1};
    bool flag,vis[maxn][maxn];
    char mp[maxn][maxn];
    bool check(int x,int y){
        if(x<0||y<0||x>=9||y>=9)return 1;
        return 0;
    }
    void dfs(int x,int y){
          if(flag)return ;
         for(int i=0;i<4;i++){
            int xx=x+ss[i][0];
            int yy=y+ss[i][1];
            if(check(xx,yy)||vis[xx][yy])continue;
            if(mp[xx][yy]=='.'){
            flag=1;return ;
            }
            if(mp[xx][yy]=='o'){
            vis[xx][yy]=1;
            dfs(xx,yy);
            if(flag)return ;
            }
         }
    }
    int main(){
    
        int T=read();
        int oo=1;
        while(T--){
            for(int i=0;i<9;i++){
                scanf("%s",mp[i]);
            }
            bool GG=0;
            for(int i=0;i<9;i++){
                for(int j=0;j<9;j++){
                    if(mp[i][j]=='.'){
                        mp[i][j]='x';
                        for(int k=0;k<4;k++){
                            mem(vis);
                            int xx=i+ss[k][0];
                            int yy=j+ss[k][1];
                            if(check(xx,yy))continue;
                            if(mp[xx][yy]=='o')
                            {
                                flag=0;
                                vis[xx][yy]=1;
                                dfs(xx,yy);
                                if(!flag){
                                    GG=1;//cout<<i<<" "<<j<<endl;
                                }
                                if(GG){break;}
                            }
                        }
                        mp[i][j]='.';
                    }  if(GG){break;}
                }  if(GG){break;}
            }
            printf("Case #%d: ",oo++);
            if(GG){
                cout<<"Can kill in one move!!!"<<endl;
            }
            else {
                cout<<"Can not kill in one move!!!"<<endl;
            }
        }
      return 0;
    }
    View Code


  • 相关阅读:
    mysql重复数据下,删除一条重复数据
    Mysql常用函数
    鼠标滑至某位置,在鼠标旁边出现详情弹窗div
    限制文本框只能输入正数,负数,小数
    JAVA中split对空串的影响。
    《JAVA与模式》之简单工厂模式 (转)
    linux 常用命令汇总
    《JAVA与模式》之责任链模式
    《JAVA与模式》之模板方法模式 (转)
    java 异常汇总
  • 原文地址:https://www.cnblogs.com/zxhl/p/4924258.html
Copyright © 2020-2023  润新知