HDU - 5546

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5546
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.

题意:
一个9*9 的棋盘,然后x代表黑棋,o代表白旗,". “代表的是空白位置;
让你用黑棋走一步就是放在(”." 空白的位置)围住白棋,当白棋周围都是黑棋时,就可以吃掉这个白棋,那么就输出Can kill in one move!!!,否则输出 Can not kill in one move!!!;
这个可以理解为围棋。
解题思路:
用搜索,这个用dfs;要搜索白棋周围是否存在一个空白的位置放一个黑棋,然后使得这个黑棋刚好可以围住白棋,那么就成功,否则就失败;

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
int vis[15][15], cnt, m, n, fx, fy, run[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
char s[15][15];
void dfs(int x, int y)
{
    if(s[x][y] == '.'){
        cnt ++;
        return ;
    }
    for(int i = 0; i<4; i++)
    {
        int a = x + run[i][0];
        int b = y + run[i][1];
        if(s[a][b] != 'x' && !vis[a][b] && a>=1 && a<=9 && b>=1 && b<=9)
        {
            vis[a][b] = 1;
            dfs(a, b);
        }
    }
}
int main()
{
    int t;
    cin>>t;
    for(int cas = 1; cas<=t; cas++)
    {
        for(int i = 0; i<=10; i++)//围住就不会有越界的影响
        {
            s[0][i] = 'x';
            s[i][0] = 'x';
            s[10][i] = 'x';
            s[i][10] = 'x';
        }
        for(int i = 1; i<=9; i++)//输入棋盘
            for(int j = 1; j<=9; j++)
                scanf(" %c", &s[i][j]);
//        for(int i = 0; i<=10;i++)
//        {
//            for(int j = 0; j<=10; j++)
//                printf("%c", s[i][j]);
//            printf("\n");
//        }
        int ok  = 0;
        for(int i = 1; i<=9; i++)//开始搜索
        {
            for(int j = 1; j<=9; j++)
            {
                if(s[i][j] == 'o')//是否是白棋
                {
                    memset(vis, 0, sizeof(vis));//这里每次进行dfs时vis标记都清零
                    cnt = 0;
                    dfs(i, j);//每个位置都进行搜索
                    if(cnt == 1)//存在一个空白的位置使得黑岂能包围白棋;
                    {
                        ok = 1;
                        break;
                    }
                }
            }
            if(ok)//搜索成功
                break;
        }
        if(ok) printf("Case #%d: Can kill in one move!!!\n", cas);
        else printf("Case #%d: Can not kill in one move!!!\n", cas);
    }
    return 0;
}
全部评论

相关推荐

2025-12-02 21:34
中南大学 Java
我这边应该算是华为第一批开奖的了,还是要11月底才开,不过今年的流程整体比去年确实要开得早,这一点还是值得表扬的。然后华为也确实很有诚意,给我这样bg的硕鼠开了15a,并且base地还是在杭州,应该是buff拉满了,但凡其他公司开的没这个高,and对象没签上海,可能真选择成为华孝子了。虽然很有诱惑力,但是这个15a的offer里面确实还是有猫腻的:1.&nbsp;薪资构成是这样的,15a&nbsp;=&nbsp;(基本工资+绩效工资)*12&nbsp;+&nbsp;10w年终,虽然绩效工资hr说100%能拿满,年终大部分都能拿满,绩效工资能拿满我可能还选择相信,但10w年终还能拿满,这我就存疑了。反正看了一圈别家的公司报价都是报一般情况下能拿多少年终,比如美团0-6个月,就报3.5个月,但是华似乎是喜欢往最高了报,所以估计10w年终拿满应该也是极少数人。2.&nbsp;公积金只交5%,并且缴纳基数还只是按基本工资交的,这里看似每个月到手的钱变多了,但是总体算下来,可能一年比别家就少拿1-2w。3.&nbsp;月末周六要加班,可以选择调休或双倍加班费,并且平常应该也会加班,感觉不大会像hr说的124能8.30下班,35能5.30下班的,云计算bu强度应该还算比较好的,估计一般情况下9-9-5吧,但是不知道并入ict后会如何。4.&nbsp;还有相关的业务线,听说8,9月份云计算bu内部已经调整了一波,好像还要并入ict下面了,感觉未来的不确定性也比较大。5.&nbsp;华为的认可度应该比不过传统的互联网大厂,技术的前瞻性应该也比不过(个人看法)。6.&nbsp;培养和升职,感觉美团可能更有说法,毕竟见到过1年升L6的,甚至还有两年升L7的,对华为的了解相对较少,只知道华为可能相对稳定一些?毕竟4年一签?综上,还是决定放弃华,准备去团吧,自己选的路,希望不会后悔吧。
变形钢筋:这个薪资结构,年终奖是画大饼啊
OC/开奖
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务