HDU 5546 Ancient Go(搜索) - dblank

HDU 5546 Ancient Go(搜索)

Ancient Go

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

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.


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.


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.




using namespace std;  
int vis[15][15], cnt, m, n, fx, fy, run[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};  
char s[15][15];  
void dfs(int x, int y)  
    //printf("%d %d\n", x, y);  
    if(s[x][y] == '.'){  
        cnt ++;  
        return ;  
    for(int i = 0; i<4; i++)  
        int a = x + run[i][0];  
        int b = y + run[i][1];  
        if(s[a][b] != 'x' && !vis[a][b] && a>=1 && a<=9 && b>=1 && b<=9)  
            vis[a][b] = 1;  
            dfs(a, b);  
int main()  
    int t;  
    for(int cas = 1; cas<=t; cas++)  
        for(int i = 0; i<=10; i++)  
            s[0][i] = 'x';  
            s[i][0] = 'x';  
            s[10][i] = 'x';  
            s[i][10] = 'x';  
        for(int i = 1; i<=9; i++)  
            for(int j = 1; j<=9; j++)  
                scanf(" %c", &s[i][j]);   
        int ok  = 0;  
        for(int i = 1; i<=9; i++)  
            for(int j = 1; j<=9; j++)  
                if(s[i][j] == 'o')  
                    memset(vis, 0, sizeof(vis));  
                    cnt = 0;  
                    dfs(i, j);  
                   // cout<<cnt<<endl;  
                    if(cnt == 1)  
                        ok = 1;  
            if(ok) break;  
        if(ok) printf("Case #%d: Can kill in one move!!!\n", cas);  
        else printf("Case #%d: Can not kill in one move!!!\n", cas);  
    return 0;