2015南阳CCPC G - Ancient Go dfs
G - Ancient Go
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
Output
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!!! 题意:下围棋规则,给你一个9*9的棋盘:上面有圈叉,现在轮到你下叉子,判断是否能够杀死至少一枚圈
题解;直接枚举所有下子的情况,判断是否叉围住了至少一个圈。……——……
///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a))
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define inf 100000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//****************************************
#define maxn 11
int ss[][]={-,,,-,,,,};
bool flag,vis[maxn][maxn];
char mp[maxn][maxn];
bool check(int x,int y){
if(x<||y<||x>=||y>=)return ;
return ;
}
void dfs(int x,int y){
if(flag)return ;
for(int i=;i<;i++){
int xx=x+ss[i][];
int yy=y+ss[i][];
if(check(xx,yy)||vis[xx][yy])continue;
if(mp[xx][yy]=='.'){
flag=;return ;
}
if(mp[xx][yy]=='o'){
vis[xx][yy]=;
dfs(xx,yy);
if(flag)return ;
}
}
}
int main(){ int T=read();
int oo=;
while(T--){
for(int i=;i<;i++){
scanf("%s",mp[i]);
}
bool GG=;
for(int i=;i<;i++){
for(int j=;j<;j++){
if(mp[i][j]=='.'){
mp[i][j]='x';
for(int k=;k<;k++){
mem(vis);
int xx=i+ss[k][];
int yy=j+ss[k][];
if(check(xx,yy))continue;
if(mp[xx][yy]=='o')
{
flag=;
vis[xx][yy]=;
dfs(xx,yy);
if(!flag){
GG=;//cout<<i<<" "<<j<<endl;
}
if(GG){break;}
}
}
mp[i][j]='.';
} if(GG){break;}
} if(GG){break;}
}
printf("Case #%d: ",oo++);
if(GG){
cout<<"Can kill in one move!!!"<<endl;
}
else {
cout<<"Can not kill in one move!!!"<<endl;
}
}
return ;
}
2015南阳CCPC G - Ancient Go dfs的更多相关文章
- 2015南阳CCPC G - Ancient Go 暴力
G - Ancient Go Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Yu Zhou likes to play Go wi ...
- 2015南阳CCPC E - Ba Gua Zhen 高斯消元 xor最大
Ba Gua Zhen Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description During the Three-Kingdom perio ...
- 2015南阳CCPC F - The Battle of Guandu 多源多汇最短路
The Battle of Guandu Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description In the year of 200, t ...
- 2015南阳CCPC L - Huatuo's Medicine 水题
L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous ...
- 2015南阳CCPC H - Sudoku 暴力
H - Sudoku Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Yi Sima was one of the best cou ...
- 2015南阳CCPC L - Huatuo's Medicine 签到
L - Huatuo's Medicine Description Huatuo was a famous doctor. He use identical bottles to carry the ...
- 2015南阳CCPC H - Sudoku 数独
H - Sudoku Description Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny g ...
- 2015南阳CCPC D - Pick The Sticks dp
D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...
- 2015南阳CCPC C - The Battle of Chibi DP
C - The Battle of Chibi Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Cao Cao made up a ...
随机推荐
- 通俗理解LDA主题模型(boss)
0 前言 看完前面几篇简单的文章后,思路还是不清晰了,但是稍微理解了LDA,下面@Hcy开始详细进入boss篇.其中文章可以分为下述5个步骤: 一个函数:gamma函数 四个分布:二项分布.多项分布. ...
- C++ 泛型程序设计与STL模板库(1)---泛型程序设计简介及STL简介与结构
泛型程序设计的基本概念 编写不依赖于具体数据类型的程序 将算法从特定的数据结构中抽象出来,成为通用的 C++的模板为泛型程序设计奠定了关键的基础 术语:概念 用来界定具备一定功能的数据类型.例如: 将 ...
- glic,uClibc,EGLIBC 简要介绍
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- spring 实例 bean 的方式
一.使用构造器实例化: <bean id="personService" class="cn.mytest.service.impl.PersonServiceBe ...
- 计算机网络(二)--HTTP详解
Web相关内容都是存储在Web服务器上,Web服务器上使用的是http协议,因此也被成为http服务器.http的client.server构成了万维网的 基本组件 一.资源 1.URI: 统一资源标 ...
- JavaScipt30(第二个案例)
承接上篇https://www.cnblogs.com/wangxi01/p/10641115.html,这是第二个案例 附上项目链接: https://github.com/wesbos/JavaS ...
- Spring Boot 2.0的属性绑定
Spring Boot2.0的属性绑定 原文从Spring boot第一个版本以来,我们可以使用@ConfigurationProperties注解将属性绑定到对象.也可以指定属性的各种不同格式.比如 ...
- 在TWaver的Tree节点上画线
论坛上有同学提出如何在tree上画引导线,之前我们Flex已经实现此功能,现在最新版的HTML5也将添加此功能.先看看效果:详细的使用方法可以参考我们开发手册中可视化视图组件#Tree引导线一章,下面 ...
- 09js、MySQL相关
09js.MySQL相关-2018/07/19 1.js的dom 理解一下文档对象模型:html文件加载到内存之后会形成一颗dom树,根据这些节点对象可以进行脚本代码的动态修改;在dom树当中 一切皆 ...
- 「 RQNOJ PID204 」 特种部队
解题思路 看了一下题解,感觉题解貌似有些错误.所以把我的见解放在这里,希望路过的大佬可以帮忙解释一下 QAQ 就是这里的更新 $dp[i-1][i]$ 和 $dp[i][i-1]$ 的时候,之前博主说 ...