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

题意 在.出放一个黑棋X能包围白棋o,只能放一个黑棋

方法 搜索白棋四周有几个空白点如果小于等于1就可以

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
#define N 200
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
char str[N][N];
int dis[4][2]= {{0,1},{1,0},{-1,0},{0,-1}};
int vis[N][N];
int pan(int x,int y)
{
    return (x>=0 && x<9 && y>=0 && y<9);
}
int dfs(int x,int y)
{
    vis[x][y]=1;int f=0;
    for(int i=0; i<4; i++)
    {
        int xx = x+dis[i][0];
        int yy = y+dis[i][1];
        if(vis[xx][yy] || !pan(xx,yy))///搜过的和坐垫不符合的跳过
            continue;
        if(str[xx][yy]==‘.‘)///有一个累加
        {
            f++;
            vis[xx][yy]=1;
        }
        if(str[xx][yy]==‘o‘)///四周白棋的四周的空白点个数
            f+=dfs(xx,yy);
    }
    return f;
}
int sove()
{
    for(int i=0; i<9; i++)
    {
        for(int j=0; j<9; j++)
        {
            if(str[i][j]==‘o‘) ///找到一个白棋搜索
            {
                met(vis,0);
                int ans=dfs(i,j);
                if(ans<=1)
                 return 1;
            }
        }
    }
    return 0;
}
int main()
{
    int t,con=1;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0; i<9; i++)
            scanf("%s",str[i]);

        int ans=sove();
        if(ans)
            printf("Case #%d: Can kill in one move!!!\n",con++);
        else
            printf("Case #%d: Can not kill in one move!!!\n",con++);
    }
    return 0;
}
时间: 2024-12-02 09:01:44

(hdu)5546 Ancient Go的相关文章

(HDU)1037 --Keep on Truckin&#39;(待在卡丁车上)

题目链接:http://vjudge.net/problem/HDU-1037 告诉你三个通道的高度和车的高度,按顺序判断能否通过. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 int main() 7 { 8 int a,b,c; 9 scanf("%d %d %d",&a,&b,&c);

(HDU)1098 -- Ignatius&#39;s puzzle(Ignatius的困惑)

题目链接:http://vjudge.net/problem/HDU-1098 求解思路: f(x)=5*x^13+13*x^5+k*a*x; 其中题中"f(x)|65"表示对于任意的整数x,f(x)都能被65整除.所以不难推断:f(x+1)|65也成立. f(x+1)=5*(x+1)^13+13*(x+1)^5+k*a*(x+1), 根据二项式定理:(a+b)^n=C(n,0)a^n+C(n,1)a^(n-1)*b+C(n,2)a^(n-2)*b^2+...+C(n,n)b^n 得:

(hdu)5391 Zball in Tina Town

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5391 Problem Description Tina Town is a friendly place. People there care about each other. Tina has a ball called zball. Zball is magic. It grows larger every day. On the first day, it becomes 1 t

(HDU)1046 -- 完数

题目链接:https://vjudge.net/problem/HDU-1406 注意是所有的因子之和,重复出现的因子不要累加(如果模拟了除法的话),另外给出的两个整数要比较大小(坑). 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <iostream> 5 #include <algorithm> 6 #include <string>

(HDU)1014 --Uniform Generator(统一随机数生成)

这个题目不难,关键是看懂英文:(判断两个数是否互质,而且注意输出的格式) 描述 计算机模拟通常需要随机数.生成伪随机数的一种方式是通过一定形式的函数: seed(x + 1)= [seed(x)+ STEP]%MOD 其中'%'是模运算符. 这样的函数将生成在0和MOD-1之间的伪随机数(种子).这种形式的作用的一个问题就是,它们将总是重复地生成相同的模式. 为了最小化这种影响,仔细选择STEP和MOD值,可以使得在0和MOD-1(包括这两者)之间的所有值的均匀分布. 例如,如果STEP = 3

(HDU)1005 -- Number Sequence(数列)

问题描述 数列定义如下: f(1)= 1,f(2)= 1,f(n)=(A * f(n-1)+ B * f(n-2))mod 7. 给定A,B和n,你要计算f(n)的值. 输入 输入由多个测试用例组成. 每个测试用例在一行(1 <= A,B <= 1000,1 <= n <= 100,000,000)中包含3个整数A,B和n.三个零表示输入结束,此测试用例不进行处理. 输出 对于每个测试用例,在一行上输出f(n)的值. 样例输入 1 1 3 1 2 10 0 0 0 样例输出 2 5

(HDU)1017 --A Mathematical Curiosity(数学好奇心)

描述 给定两个整数n和m,计数整数对(a,b)的数目,使得0 <a <b <n,并且(a ^ 2 + b ^ 2 + m)/(ab)是一个整数. 这个问题包含多个测试用例! 输入的第一行是整数N,然后是空白行,后跟N个输入块. 每个输入块采用问题说明中指示的格式. 输入块之间有空行. 输出格式由N个输出块组成. 输出块之间有一个空行. 输入 您将在输入中获得多个样例. 每个情况由包含整数n和m的行指定. 输入结束由n = m = 0的情况表示.您可以假设0 <n <= 100

(HDU)1040 --As Easy As A+B(像A+B一样简单)

题目链接:http://vjudge.net/problem/HDU-1040 思路:排序算法的水题.注意输出格式,数字之间有空格. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 int main() 7 { 8 int n,num,i,j,temp; 9 int s[1010]; 10 scanf("%d",&

(HDU)1061 --Rightmost Digit( 最右边的数字)

题目链接:http://vjudge.net/problem/HDU-1061 这个题目要求出N个N相乘的个位,直接求结果肯定数据溢出. 其实只要每次得出一个数字保留个位和N相乘就可以了, 因为A*B=C,对于个位而言,A(个位)*B(个位)=C(个位)始终成立. 1<=N<=1,000,000,000,这样写还是TLE了. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 us