CCPC Ancient Go

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 and output

Sample Input Sample Output
2

.......xo
.........
.........
..x......
.xox....x
.o.o...xo
..o......
.....xxxo
....xooo.

......ox.
.......o.
...o.....
..o.o....
...o.....
.........
.......o.
...x.....
........o
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.

#include<cstdio>
#include<cstring>
#include<stack>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int oo = 1e9+7;
const int maxn = 3*1e6+7;
int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
int vis[20][20];
char maps[20][20];
int judge(int x, int y)
{
    vis[x][y] = 1;
    int i, sx, sy;
    for(i = 0; i < 4; i++)
    {
        sx = x + dir[i][0];
        sy = y + dir[i][1];
        if(sx < 0 || sx >= 9 || sy < 0 || sy >= 9 || vis[sx][sy]) continue;
        if(maps[sx][sy] == ‘.‘) return 0;
        if(maps[sx][sy] == ‘o‘ && !judge(sx, sy)) return 0;

    }
    return 1;
}
int dfs(int x, int y)
{
    int i;
    for(i = 0; i < 4; i++)
    {
        int sx, sy;
        sx = x+dir[i][0];
        sy = y+dir[i][1];
		if(maps[sx][sy] == ‘o‘)
        if(sx >= 0 && sx < 9 && sy >= 0 && sy < 9)
        {
            memset(vis, 0, sizeof(vis));
            if(judge(sx, sy))
                return 1;
        }
    }
    return 0;
}
int main()
{
    int T, i, j, cas = 1, ok;
    scanf("%d", &T);
    while(T--)
    {
        ok = 0;
        for(i = 0; i < 9; i++)
            scanf("%s", maps[i]);

        for(i = 0; i < 9; i++)
        {
            for(j = 0; j < 9; j++)
            {
                if(maps[i][j] == ‘.‘)
                {
					maps[i][j] = ‘x‘;
                    ok = dfs(i, j);
					maps[i][j] = ‘.‘;
                }
                if(ok == 1) break;
            }
            if(ok == 1)break;
        }
        if (ok == 1) 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-10-16 15:13:37

CCPC Ancient Go的相关文章

poj 2159 D - Ancient Cipher 文件加密

Ancient Cipher Description Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping

Ancient Printer(tire树)

Ancient Printer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 1511    Accepted Submission(s): 748 Problem Description The contest is beginning! While preparing the contest, iSea wanted to pri

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

uva--1339 - Ancient Cipher(模拟水体系列)

1339 - Ancient Cipher Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping. The

ural 1249. Ancient Necropolis

1249. Ancient Necropolis Time limit: 5.0 secondMemory limit: 4 MB Aerophotography data provide a bitmap picture of a hard-to-reach region. According to the suggestions of scientists, this region is a cemetery of an extinct civilization. Indeed, the p

UVa 1339 Ancient Cipher --- 水题

UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要,可以分别统计两个字符串中的各个字母出现的次数,得到两个cnt[26]数组, 又由于可以进行映射,则可以直接对两个数组进行排序后判断是否相等(相当于原来相等的值的两个地方做映射) /* UVa 1339 Ancient Cipher --- 水题 */ #include <cstdio> #incl

poj 2159 Ancient Cipher(水)

Ancient Cipher Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30695   Accepted: 10023 Description Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents w

UVa 1339 Ancient Cipher【排序】

/* 中文题目      古老的密码 中文翻译-大意  给你两个字符串,看你能不能将第一个字符变化位置(重排),变成和第二个字符串的26个字母一一对应. 解题思路:将两个字符串的各个字符的数量统计出来,如果各个字符串的数量都是一样的,那么就输出yes,否则输出no 难点详解:在统计每个字符出现的次数有点小难度 关键点:排序 解题人:lingnichong 解题时间:2014/08/26    00:36 解题体会:很好的一题 */ 1339 - Ancient Cipher Time limit

UVa1399.Ancient Cipher

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4085 13855995 1339 Ancient Cipher Accepted C++ 0.012 2014-07-09 12:35:33 Ancient Cipher Ancient Roman empire had a strong government system wit