HDU 5546/ancient Go

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Problem Description
Yu Zhou likes to play Go with 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 be put on the intersection of the board lines, so there is 9x9 dif Ferent 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≤100). T 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. ′x′represents a cell with black chess which owned by Yu Zhou. ′o′represents a cell with the 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.
.....
..... o
Sample Output
Case #1: Can kill in one move!!!

Case #2: Can not kill in one move!!!

Pit Point one: be input pit dead, with gets infinite W, still don't understand why ...

Pit point two: note '. ' When to mark. Both a connected block cannot continuously access a '. '.


#include <iostream> #include <stdio.h> #include <string.h>using namespace Std;char s[25][25];int f[4]    [2]= {{1,0},{-1,0},{0,1},{0,-1}};int sum,v,vis[25][25];void dfs (int x,int y) {vis[x][y]=1;    int A, B;        for (int i=0; i<4; i++) {a=x+f[i][0],b=f[i][1]+y;            if (a>=0&&a<9&&b>=0&&b<9&&!vis[a][b]&&s[a][b]!= ' x ') {            if (s[a][b]== '. ')                {vis[a][b]=1;            sum=sum+1;            } else {Dfs (A, b);    }}}}int Main () {int t,b;    cin>>t;////getchar ();        for (int t=1; t<=t; t++) {//gets (s[0]);        Cin.get ();        memset (vis,0,sizeof (VIS));        b=0;        V=1; for (int i=0; i<9; i++)//scanf ("%s", S[i]);           Gets (S[i]);        cin>>s[i];      for (int i=0, i<9; i++) {for (int j=0; j<9; J + +) {          if (s[i][j]== ' O ' &&!vis[i][j]) {memset (vis,0,sizeof (VIS));                    V+=1;                    sum=0;                    DFS (I,J);                        if (sum==1) {b=1;                        i=10;                    Break        }}}} printf ("Case #%d:", t); if (B) printf ("Can kill in one move!!!        \ n "); else printf ("Can not kill in one move!!!    \ n "); } return 0;}


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.