HDU 5546 Ancient Go DFS

Source: Internet
Author: User
Tags cas

Ancient Go

Time limit:3000/1000 MS (java/others) Memory limit:65535/65535 K (java/others)
Total submission (s): 1732 Accepted Submission (s): 552


Problem Descriptionyu 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 a8x8 Cell board, the chess can be put in the intersection of the board lines, so there is9x9 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.

Inputthe 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.An o -Represents a cell with the white chess which owned by Su Lu.

Outputfor each test case, output one line containing Case #x: y, where x is the test Case number (starting from 1) and y are Can kill in one move!!! if Yu en OU have a move to kill at least one of Su Lu's components.  Can not kill in one move!!! otherwise.

Sample input2.......xo....................x.......xox....x.o.o ... Xo..  O...........xxxo....xooo. ... ox........o....o.......o.o.......o.....................o....x.............o

Sample outputcase #1: Can kill in one move!!! Case #2: Can not kill in one move!!! HintIn 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.   Sourcethe China Collegiate Programming Contest Recommendwange2014 | We have carefully selected several similar problems for you:5981 5980 5979 5978 5977 Look back for a long time not to write a puzzle after the provincial game is too corrupt today began to re-work to brush Problem or soon become a salted fish this problem is the rules of go to go to the rule asked can be given in a step to kill at least one piece we can convert to white chess how many pores greater than or equal to 2 words can not be killed so we directly traverse the board of White Chess and then to their DFS can be
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < queue> #include <vector> #include <iomanip> #include <math.h> #include <map>using namespace STD; #define FIN freopen ("Input.txt", "R", stdin), #define FOUT freopen ("Output.txt", "w", stdout); #define INF 0x3f3f 3f3f#define infll 0x3f3f3f3f3f3f3f#define Lson l,m,rt<<1#define rson m+1,r,rt<<1|1typedef Long Long LL ; typedef pair<int, int> Pii;char chess[15][15];int vis[15][15];int flag, Num;//xobool Check (int x, int y) {retur n x >= 0 && x <= 8 && y >= 0 && y <= 8 && chess[x][y]! = ' x ' && vis[x] [y] = = 0;}    void Llss (int x, int y) {if (num >= 2) return;        if (check (x, y)) {vis[x][y] = 1;            if (chess[x][y] = = ' O ') {LLSS (x + 1, y);            LLSS (x-1, y);            LLSS (x, y + 1);        LLSS (x, y-1);      } else {num++;  }} else return;}    int main () {//fin int T;    int cas = 1;    scanf ("%d", &t);        while (t--) {flag = 0;        for (int i = 0; i < 9; i++) scanf ("%s", Chess[i]);                for (int i = 0; i < 9; i++) {for (int j = 0; J < 9; J + +) {memset (Vis, 0, sizeof (VIS));                num = 0;                if (chess[i][j] = = ' O ' && flag = = 0) Llss (i, j);                    if (num = = 1) {flag = 1;                Break }}} if (flag) printf ("Case #%d:can kill in one move!!!        \ n ", cas++); else printf ("Case #%d:can isn't kill in one move!!!    \ n ", cas++); }}

  

HDU 5546 Ancient Go DFS

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.