CCPC Ancient Go

Source: Internet
Author: User

Yu Zhou likes to play with Go Su Lu. From the historical, we found this there is much difference on the rules between ancient go and modern go.

Here are the rules for ancient go they were playing:

  • The game is played on a 8x8 Cell Board, the chess can was put on the intersection of the Board lines, so there is 9x9 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'll 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 is 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 have a move to kill at least one of Su Lu ' s Che Ss.

Input

The first line of the input gives the number of test cases,T(1≤T≤ ).TTest cases follow. Test cases is separated by a 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. orepresents a cell with the white chess which owned by Su Lu.

Output

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

Sample Input and output
Sample Input Sample Output
2.......XO....................X.......XOX....X.O.O ... Xo.. o...........xxxo....xooo.......ox........o....o.......o.o.......o.....................o....x.............o
Case #1: Can kill in one move!!! Case #2: Can not kill in one move!!!
Hint

In the first test case, Yu Zhou have 4 different ways to kill Su Lu ' s component.

The

In the second-test case, there is no-the-to kill Su Lu ' s component.

#include <cstdio> #include <cstring> #include <stack> #include <vector> #include <queue># include<cmath> #include <cstdlib> #include <iostream> #include <algorithm>using namespace std; const int OO = 1e9+7;const int maxn = 3*1e6+7;int Dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};int Vis[20][20];char maps[20][20    ];int judge (int x, int y) {vis[x][y] = 1;    int i, SX, SY;        for (i = 0; i < 4; i++) {SX = x + dir[i][0];        Sy = y + dir[i][1];        if (SX < 0 | | SX >= 9 | | Sy < 0 | | Sy >= 9 | | vis[sx][sy]) continue;        if (maps[sx][sy] = = '. ') return 0;    if (maps[sx][sy] = = ' O ' &&!judge (SX, SY)) return 0; } return 1;}    int dfs (int x, int y) {int i;        for (i = 0; i < 4; i++) {int sx, SY;        SX = x+dir[i][0]; sy = y+dir[i][1];if (Maps[sx][sy] = = ' O ') if (SX >= 0 && SX < 9 && sy >= 0 && Sy &lt ; 9) {memset (Vis, 0, sizeof (VIS));        if (Judge (SX, SY)) return 1; }} return 0;}    int main () {int T, I, j, cas = 1, OK;    scanf ("%d", &t);        while (t--) {ok = 0;        for (i = 0; i < 9; i++) scanf ("%s", Maps[i]);                 for (i = 0; i < 9; i++) {for (j = 0; J < 9; J + +) {if (maps[i][j] = = '. ')                    {Maps[i][j] = ' x ';                OK = DFS (i, j); maps[i][j] = '. ';            } if (ok = = 1) break;        } if (ok = = 1) break; if (ok = = 1) printf ("Case #%d:can kill in one move!!!        \ n ", cas++); else printf ("Case #%d:can isn't kill in one move!!!    \ n ", cas++); } return 0;}

  

CCPC Ancient Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.