hdu---5546---Ancient Go

题目链接:

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

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  cell board, the chess can be put on the intersection of the board lines, so there are  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,  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.  represents a cell with black chess which owned by Yu Zhou.  represents a cell with white chess which owned by Su Lu.

Output

For each test case, output one line containing Case #x: y, where  is the test case number (starting from 1) and  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.


真是要疯了,一道题并不难的题,由于题意一直读不懂,愣是弄了快3个小时才OK

Mean:

我方棋子是‘x‘,敌方是‘o‘。现在轮到我方落子,问我方能不能在下一回合吃掉对方的至少一个棋子。

吃掉的规则是:对方被围的棋子在下一回合时已经找不到为‘ . ‘的位置,就是我下一个棋子把‘o’包围了。

范围:棋盘大小9*9。

Analse:

枚举每一个‘.‘,使其变成‘x‘,在这一点周围四个点为方向进行DFS,遇到‘x‘返回,如果存在一个DFS过程中没发现‘.‘即存在。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;
typedef long long LL;

const int maxn=1000005;
const int INF=0x3f3f3f3f;

char maps[10][10];
int vis[10][10];
int dir[4][2]= {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int f;

void DFS(int x, int y)
{
    vis[x][y]=1;

    if(maps[x][y]==‘.‘)
    {
        f=1;
        return ;
    }

    if(maps[x][y]==‘x‘)return ;

    for(int i=0; i<4; i++)
    {
        int nx=x+dir[i][0];
        int ny=y+dir[i][1];

        if(nx>=0&&nx<9&&ny>=0&&ny<9&&!vis[nx][ny])
            DFS(nx, ny);
    }
}
int solve()
{
    for(int i=0; i<9; i++)
    {
        for(int j=0; j<9; j++)
        {
            if(maps[i][j]==‘.‘)///枚举每一个‘.‘
            {
                maps[i][j]=‘x‘;///将其变成黑棋
                for(int k=0; k<4; k++)
                {
                    int nx=i+dir[k][0];
                    int ny=j+dir[k][1];

                    if(nx>=0&&nx<9&&ny>=0&&ny<9&&maps[nx][ny]==‘o‘)///寻找‘.‘周围合法的白棋
                    {
                        memset(vis, 0, sizeof(vis));
                        f=0;
                        DFS(nx, ny);///判断白棋是否能够被我方黑棋包围
                        if(!f)
                            return 1;
                    }
                }
                maps[i][j]=‘.‘;///如果其周围没有白棋或者黑棋包围白棋不成功,还要将其还原为‘.‘
            }
        }
    }
    return 0;
}
int main()
{
    int T, cas=1;
    scanf("%d", &T);

    while(T--)
    {
        for(int i=0; i<9; i++)
            scanf("%s", maps[i]);

        int ans=solve();
        if(ans)printf("Case #%d: Can kill in one move!!!\n", cas++);
        else
            printf("Case #%d: Can not kill in one move!!!\n", cas++);
    }
    return 0;
}
时间: 2024-12-06 23:16:48

hdu---5546---Ancient Go的相关文章

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 tha

(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

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 3460 Ancient Printer

答案=字典树节点个数+单词个数-最长的单词的长度.表示不会推倒.看了大牛博客. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; struct shu{ int nn[27]; }node[500010]; int ii, i, n, m, zz, tott, hh; char s[10000]; int main() { w

Ancient Printer HDU - 3460 贪心+字典树

The contest is beginning! While preparing the contest, iSea wanted to print the teams' names separately on a single paper. Unfortunately, what iSea could find was only an ancient printer: so ancient that you can't believe it, it only had three kinds

HDU 4772 Zhuge Liang&#39;s Password

Problem Description In the ancient three kingdom period, Zhuge Liang was the most famous and smart military leader. His enemy was Sima Yi, the military leader of Kingdom Wei. Sima Yi always looked stupid when fighting against Zhuge Liang. But it was

HDU 4472 Count(数学 递归)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4472 Problem Description Prof. Tigris is the head of an archaeological team who is currently in charge of an excavation in a site of ancient relics. This site contains relics of a village where civilizat

【深搜加剪枝五】HDU 1010 Tempter of the Bone

Tempter of the BoneTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 64326    Accepted Submission(s): 17567 Problem Description The doggie found a bone in an ancient maze, which fascinated him a l

hdu 3466 Proud Merchants(0-1背包+排序)

题目来源:hdu 3466 Proud Merchants Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 3595 Accepted Submission(s): 1500 Problem Description Recently, iSea went to an ancient country. For

hdu 5294 Tricks Device 最短路建图+最小割

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5294 Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 375    Accepted Submission(s): 98 Problem Description Innocent Wu follows Dumb Zh