HDU 5546 Ancient Go DFS

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 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.

Input

The first line of the input gives the number of test cases, T(1≤T≤100). 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.

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.

...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 has 4 different ways to kill Su Lu‘s component.

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

Source

The 2015 China Collegiate Programming Contest

Recommend

wange2014   |   We have carefully selected several similar problems for you:  5981 5980 5979 5978 5977

回头看一下好久没写题解了  省赛之后太堕落了 今天开始要重新努力刷题了不然很快就变成一条咸鱼了

这条题就是围棋的规则 问能不能在给出的情况下用一步来干掉至少一个棋子

我们可以转换为求白棋有多少个气孔 大于等于2个的话就不能被干掉 这样的话我们直接遍历棋盘里面的白棋 然后对他们进行dfs就可以了

#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     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;

char chess[15][15];
int vis[15][15];
int flag, num;
//xo

bool check(int x, int y) {
    return 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 not kill in one move!!!\n", cas++);

    }

}

  

时间: 2024-10-29 19:12:03

HDU 5546 Ancient Go DFS的相关文章

hdu 1501 Zipper (dfs+记忆化搜索)

Zipper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6491    Accepted Submission(s): 2341 Problem Description Given three strings, you are to determine whether the third string can be formed

hdu 1518 Square (dfs搜索可参考poj1011)

Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8589    Accepted Submission(s): 2784 Problem Description Given a set of sticks of various lengths, is it possible to join them end-to-end

G - Ancient Go HDU - 5546 DFS

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×88×8 cell board,

(hdu)5546 Ancient Go

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

hdu 5167 Fibonacci(DFS)

hdu 5167 Fibonacci 问题描述 斐波那契数列的递归定义如下: Fi=???01Fi?1+Fi?2i = 0i = 1i > 1 现在我们需要判断一个数是否能表示为斐波那契数列中的数的乘积. 输入描述 有多组数据,第一行为数据组数T(T≤100,000). 对于每组数据有一个整数n,表示要判断的数字. 0≤n≤1,000,000,000 输出描述 对于每组数据,如果可以输出"Yes",否则输出"No". 输入样例 3 4 17 233 输出样例

HDU 3158 PropBot(DFS)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3158 Problem Description You have been selected to write the navigation module for PropBot. Unfortunately, the mechanical engineers have not provided a lot of flexibility in movement; indeed, the PropBot

hdu 4499 Cannon 暴力dfs搜索

Cannon Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 589    Accepted Submission(s): 338 Problem Description In Chinese Chess, there is one kind of powerful chessmen called Cannon. It can move

K - Ancient Messages(dfs求联通块)

K - Ancient Messages Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 1103 Appoint description: Description In order to understand early civilizations, archaeologists often study texts written in ancie

Hdu 1175 连连看(DFS)

Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1175 因为题目只问能不能搜到,没问最少要几个弯才能搜到,所以我采取了DFS. 因为与Hdu 1728相比,都要考虑转弯次数,所以在判断转弯的次数上,两者可以相互借鉴. 这一点应该不难想到,在搜索前就应判断两点的值是否相等,以及两点的值中是否有0.如果不相等或其中一值为0,则可以判断是"NO". 时间虽是10000ms,但只是这样,还是超时. 后来又加了一个数组walk[][],用