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. 使用Jenkins+Pipline 持构建自动化部署之安卓源码打包、测试、邮件通知

    一.引言 Jenkins 2.x的精髓是Pipeline as Code,那为什么要用Pipeline呢?jenkins1.0也能实现自动化构建,但Pipeline能够将以前project中的配置信息 ...

  2. Java并发/多线程-CAS原理分析

    目录 什么是CAS 并发安全问题 举一个典型的例子i++ 如何解决? 底层原理 CAS需要注意的问题 使用限制 ABA 问题 概念 解决方案 高竞争下的开销问题 什么是CAS CAS 即 compar ...

  3. 目前用下来最溜的MacOS微信多开工具!

    一个生活微信,一个工作微信是很多上班族的基本配置. 但由于微信客户端在PC端上只能打开一个,这使得在上班时候就非常不便,一个号在PC端上登录,一个在手机上使用,但是上班时候又不能一直看手机,不然老板还 ...

  4. python sqlite3增加表字段

    给sqlite3表格增加新字段,要注意大小写,要不然不成功. 一开始这样写,不成功! 后面规范写,按大小写严格规范写! 成功了!现在查看新增加的字段commit: 仔细看,这下全部小写,括表名称.co ...

  5. 浏览器performance工具介绍及内存问题表现与监控内存的几种方式

    一.GC的目的 为了实现内存空间的良性循环,performance提供多种监控方式监控内存 分析内存相关信息 当代码出现问题的时候及时定位到出现问题的代码块, 提高执行效率. preforcemanc ...

  6. 解决ubuntu获取root账号并开通ssh

    1.设置root密码 sudo passwd root 2.修改etc/ssh/sshd_config文件 su - root vi /etc/ssh/sshd_config LoginGraceTi ...

  7. 词嵌入之FastText

    什么是FastText FastText是Facebook于2016年开源的一个词向量计算和文本分类工具,它提出了子词嵌入的方法,试图在词嵌入向量中引入构词信息.一般情况下,使用fastText进行文 ...

  8. 入门OJ:亲戚

    题目描述 或许你并不知道,你的某个朋友是你的亲戚.他可能是你的曾祖父的外公的女婿的外甥女的表姐的孙子.如果能得到完整的家谱,判断两个人是否亲戚应该是可行的,但如果两个人的最近公共祖先与他们相隔好几代, ...

  9. 图解 ECDHE 密钥交换算法

    HTTPS 常用的密钥交换算法有两种,分别是 RSA 和 ECDHE 算法. 其中,RSA 是比较传统的密钥交换算法,它不具备前向安全的性质,因此现在很少服务器使用的.而 ECDHE 算法具有前向安全 ...

  10. Java中,那些关于String和字符串常量池你不得不知道的东西

    老套的笔试题 在一些老套的笔试题中,会要你判断s1==s2为false还是true,s1.equals(s2)为false还是true. String s1 = new String("xy ...