Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit 
Status

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.

Source

The 2015 China Collegiate Programming Contest
这题可以用宽搜,枚举所有能放'x'旗子的位置,然后看看有没有'o'被围住。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 0x7fffffff
#define maxn 12
char s[maxn][maxn];
int vis[maxn][maxn];
int tab[4][2]={0,1,-1,0,0,-1,1,0}; int bfs(int x1,int y1)
{
int i,j,xx,yy,front,rear,flag=1,x,y;
int q[1111][2];
front=rear=1;
q[front][0]=x1;q[front][1]=y1; while(front<=rear){
x=q[front][0];
y=q[front][1];
front++;
for(i=0;i<4;i++){
xx=x+tab[i][0];
yy=y+tab[i][1];
if(xx>=1 && xx<=9 && yy>=1 && yy<=9 && !vis[xx][yy] && s[xx][yy]!='x'){
if(s[xx][yy]=='.'){
flag=0;
}
else{
vis[xx][yy]=1;
rear++;
q[rear][0]=xx;q[rear][1]=yy;
} } }
}
return flag; } int check()
{
int i,j,flag;
memset(vis,0,sizeof(vis));
flag=0;
for(i=1;i<=9;i++){
for(j=1;j<=9;j++){
if(s[i][j]=='o' && !vis[i][j]){
vis[i][j]=1;
flag=bfs(i,j);
if(flag)break;
}
}
if(flag)break;
}
return flag;
} int main()
{
int i,j,T,k,h,flag,cas=0;
scanf("%d",&T);
while(T--)
{
for(i=1;i<=9;i++){
scanf("%s",s[i]+1);
}
flag=0;
for(i=1;i<=9;i++){
for(j=1;j<=9;j++){
if(s[i][j]=='.'){
s[i][j]='x';
flag=check();
if(flag){
break;
}
else{
s[i][j]='.';
}
}
}
if(flag)break;
}
cas++;
if(flag){
printf("Case #%d: Can kill in one move!!!\n",cas);
}
else{
printf("Case #%d: Can not kill in one move!!!\n",cas);
}
}
return 0;
}

uestc 1221 Ancient Go的更多相关文章

  1. CDOJ 1221 Ancient Go

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1221 题目分类:dfs 代码: #include<bits/stdc++.h> using na ...

  2. BZOJ 1221: [HNOI2001] 软件开发

    1221: [HNOI2001] 软件开发 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1428  Solved: 791[Submit][Stat ...

  3. Ancient Printer[HDU3460]

    Ancient Printer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Tot ...

  4. 【英语学习】2016.09.11 Culture Insider: Teacher's Day in ancient China

      Culture Insider: Teacher's Day in ancient China 2016-09-10 CHINADAILY Today is the 32nd Chinese Te ...

  5. ACM:UESTC - 649 括号配对问题 - stack

      UESTC - 649  括号配对问题 Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu ...

  6. Good Bye 2015 D. New Year and Ancient Prophecy

    D. New Year and Ancient Prophecy time limit per test 2.5 seconds memory limit per test 512 megabytes ...

  7. UESTC 1015 Lweb and pepper --前,后缀最值

    题意: n种食物,每种含花椒的概率为Pi,现在已经选择了[L,R]这个区间(下标)的食物,要再选一个,使总的食物只有一种含花椒的概率最大,问选哪个最好,相同的选下标小的. 解法: 就不写解法了.此处有 ...

  8. 紫书例题-Ancient Cipher

    Ancient Roman empire had a strong government system with various departments, including a secret ser ...

  9. UESTC 1852 Traveling Cellsperson

    找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...

随机推荐

  1. 剑指offer 面试题5:替换空格

    题目描述 请实现一个函数,将一个字符串中的每个空格替换成"%20".例如,当字符串为We Are Happy. 则经过替换之后的字符串为We%20Are%20Happy. 编程思想 ...

  2. 机器学习算法-logistic回归算法

    Logistic回归算法调试 一.算法原理 Logistic回归算法是一种优化算法,主要用用于只有两种标签的分类问题.其原理为对一些数据点用一条直线去拟合,对数据集进行划分.从广义上来讲这也是一种多元 ...

  3. 【Java并发集合】ConcurrentHashMap源码解析基于JDK1.8

    concurrentHashMap(基于jdk1.8) 类注释 所有的操作都是线程安全的,我们在使用时无需进行加锁. 多个线程同时进行put.remove等操作时并不会阻塞,可以同时进行,而HashT ...

  4. js的函数-function

    function函数 function的英文是[功能],[数] 函数:职责:盛大的集会的意思 在js里,就是函数的意思.在Java里叫做方法. 定义函数 function fun(参数){ //函数体 ...

  5. ES6 自定义一个实现了Iterator接口的对象

    参考资料 var obj = { data: [1,2,3,4,5], // 这里实际上就是去定义如何实现Iterator接口 [Symbol.iterator](){ const that = th ...

  6. 【Linux】if中的逻辑运算符怎么在linux的帮助中看到

    今天在写shell的时候,突然想查看下if相关的一些逻辑运算的,像-f -d之类的这种 于是man if  或者if --help 可是返回的信息却都无济于事,一点帮助都没有 回想一下,if中调的判断 ...

  7. 【Linux】awk想打印制定列以后的所有列

    今天偶然研究awk,有一个文件,文件内容是全篇的1 2 3 4 5 6 7 8 9 0 现在想打印除了第一列意外的所有列 文件内容: [root@localhost ~]# cat test.txt ...

  8. ctfhub技能树—web前置技能—http协议—302跳转

    开启靶机 打开环境,查看显示 点击Give me Flag后发生跳转 根据题目提示为HTTP临时重定向 简单记录一下HTTP临时重定向是什么 HTTP重定向:服务器无法处理浏览器发送过来的请求(req ...

  9. EF Core 6.0的新计划

    今天,我们很兴奋地与你分享Entity Framework Core 6.0的计划. 这个计划汇集了许多人的意见,并概述了我们打算在哪里以及如何优化实体框架(EF Core) 6.0版本.这个计划并不 ...

  10. Kubernetes之GlusterFS集群文件系统高可用安装,提供动态卷存储

    GlusterFS高可用安装 一. 准备工作 安装好的k8s集群,提供其中三个节点给GFS,这三个节点都至少有一个可用的裸块设备 在k8s所有节点安装所需要的组件 # ubuntu16.04 add- ...