HDU---5546---Ancient Go

Source: Internet
Author: User
Tags cas

Topic Links:

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

Description

Yu Zhou likes to play GoWith 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 aCell board, the chess can be put in the intersection of the board lines, so there isDifferent 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, .Test 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.represents a cell with black chess which owned by Yu Zhou. represents a cell with the white chess which owned by Su Lu.

Output

For each test case, the output one line containing Case #x: y, where  is The test Case number (starting from 1) and < Span class= "Mathjax_preview" > < /span>  is  Can kill in one move!!!  if Yu Zhou have a move to kill at least one of Su Lu ' s components.&NBSP; 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 have 4 different ways to kill Su Lu ' s component. In the second-test case, there is the no---to kill Su Lu ' s component.

Really to be crazy, a problem is not difficult, because test instructions has been read not understand, Leng got a quick 3 hours just OK

Mean:

Our pawn is ' x ' and the enemy is ' o '. Now it's our turn to Lazi and ask if we can eat at least one of the other's pieces in the next round.

The rule of eating is that the opponent is surrounded by a piece that has not been found for the next round. ' The position of my next pawn is to surround ' o '.

Range: Checkerboard Size 9*9.

Analse:

Enumerate each '. ', make it ' X ', at this point around four points for the direction of Dfs, encounter ' x ' returned, if there is a DFS process not found '. ' is present.

#include <cstdio>#include<cstring>#include<iostream>#include<cmath>#include<vector>#include<queue>#include<algorithm>using namespaceStd;typedefLong LongLL;Const intmaxn=1000005;Const intinf=0x3f3f3f3f;Charmaps[Ten][Ten];intvis[Ten][Ten];intdir[4][2]= {{1,0}, {-1,0}, {0,1}, {0, -1}};intF;voidDFS (intXinty) {Vis[x][y]=1; if(maps[x][y]=='.') {f=1; return ; }    if(maps[x][y]=='x')return ;  for(intI=0; i<4; i++)    {        intnx=x+dir[i][0]; intny=y+dir[i][1]; if(nx>=0&&nx<9&&ny>=0&&ny<9&&!Vis[nx][ny])    DFS (NX, NY); }}intsolve () { for(intI=0; i<9; i++)    {         for(intj=0; j<9; J + +)        {            if(maps[i][j]=='.')///enumerate each '. '{Maps[i][j]='x';///turn it into black chess                 for(intk=0; k<4; k++)                {                    intnx=i+dir[k][0]; intny=j+dir[k][1]; if(nx>=0&&nx<9&&ny>=0&&ny<9&&maps[nx][ny]=='o')///looking for '. ' Around the legal white chess{memset (Vis,0,sizeof(VIS)); F=0; DFS (NX, NY);///Judging whether White can be surrounded by our black chess                        if(!f)return 1; }} Maps[i][j]='.';///If there is no white or black around the white chess is not successful, but also to restore it to '. '            }        }    }    return 0;}intMain () {intT, cas=1; scanf ("%d", &T);  while(t--)    {         for(intI=0; i<9; i++) scanf ("%s", Maps[i]); intans=solve (); if(ANS) printf ("Case #%d:can kill in one move!!! \ n", cas++); Elseprintf ("Case #%d:can isn't kill in one move!!! \ n", cas++); }    return 0;}

HDU---5546---Ancient Go

Related Article

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.