uestc 1221 Ancient Go
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
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, where x is
#x: y
the test case number (starting from 1)
and y is Can if Yu Zhou has a move to kill at least one of Su Lu's components.
kill in one move!!!Can otherwise.
not kill in one move!!!
Sample input and output
| Sample Input | Sample Output |
|---|---|
2 .......xo |
Case #1: Can 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
#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的更多相关文章
- CDOJ 1221 Ancient Go
题目链接:http://acm.uestc.edu.cn/#/problem/show/1221 题目分类:dfs 代码: #include<bits/stdc++.h> using na ...
- BZOJ 1221: [HNOI2001] 软件开发
1221: [HNOI2001] 软件开发 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1428 Solved: 791[Submit][Stat ...
- Ancient Printer[HDU3460]
Ancient Printer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Tot ...
- 【英语学习】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 ...
- ACM:UESTC - 649 括号配对问题 - stack
UESTC - 649 括号配对问题 Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu ...
- 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 ...
- UESTC 1015 Lweb and pepper --前,后缀最值
题意: n种食物,每种含花椒的概率为Pi,现在已经选择了[L,R]这个区间(下标)的食物,要再选一个,使总的食物只有一种含花椒的概率最大,问选哪个最好,相同的选下标小的. 解法: 就不写解法了.此处有 ...
- 紫书例题-Ancient Cipher
Ancient Roman empire had a strong government system with various departments, including a secret ser ...
- UESTC 1852 Traveling Cellsperson
找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...
随机推荐
- 【Git】5、Git如何提交代码到远程仓库
提交代码:如何把修改后的代码提交到远程仓库 文章目录 提交代码:如何把修改后的代码提交到远程仓库 1.同步远程代码 2.检查改动文件 3.添加文件到缓存 4.提交代码 5.推送代码 6.我的整个流程 ...
- 01-CentOS 8.1安装 Docker
官方参考地址:https://docs.docker.com/install/linux/docker-ce/centos/ 里面包含包下载地址:https://download.docker.com ...
- pscp 从win10远程传输文件到centos7,多个虚拟机之间传文件
一.将下载的pscp.exe拷贝到C:\Windows\System32 上传文件 win10 --> linux1 C:\Users\xy>pscp C:\BaiduNetdiskDow ...
- 7行代码解决P1441砝码称重(附优化过程)
先贴上最终代码感受一下: #include <bits/stdc++.h> using namespace std; int i, N, M, wi[21], res = 0; int m ...
- 前端知识(一)06 element-ui-谷粒学院
目录 一.element-ui 二.element-ui实例 1.引入脚本库 2.引入css 3.引入js 4.渲染讲师列表 5.浏览器中运行 一.element-ui element-ui 是饿了么 ...
- Android 8.0/9.0 wifi 自动连接评分机制
前言 Android N wifi auto connect流程分析 Android N selectQualifiedNetwork分析 Wifi自动连接时的评分机制 今天了解了一下Wifi自动连接 ...
- Flutter--Flutter中Widget、App的生命周期
前言 在App的开发过程中,我们通常都需要了解App以及各个页面的生命周期,方便我们在App进入前台时启动一些任务,在进入后台后暂停一些任务.同时,各个页面的生命周期也很重要,每个页面消失时要做一些内 ...
- 京东热 key 探测框架新版发布,单机 QPS 可达 35 万
https://mp.weixin.qq.com/s/3URAvUF6zwxeF5Kkc1aWHA 京东热 key 探测框架新版发布,单机 QPS 可达 35 万 原创 Hollis Hollis 2 ...
- Git提交代码规范 而且规范的Git提交历史,还可以直接生成项目发版的CHANGELOG(semantic-release)
Git提交代码规范 - 木之子梦之蝶 - 博客园 https://www.cnblogs.com/liumengdie/p/7885210.html Commit message 的格式 Git 每次 ...
- Vim配置及其他注意事项
常用的一些配置 set t_ti= set t_te= "这两个比较特殊,后边说 set termencoding=utf-8 set encoding=utf-8 set fileenco ...