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 ...
随机推荐
- 动态设置缩放比例和html字体大小
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...
- PHP填坑
这里记录下最近PHP踩过的坑,很多都是语法性错误 (1)函数结尾忘记加: 例如匿名函数 <?php $show = function($value){ echo $value."你好& ...
- ansible结合playbook批量部署war包项目上线
批量部署jenkins.war包实现上线 用于测试war包上线 [root~localhost]~#vim /etc/ansible/test.yml - hosts: test vars: ...
- 继 S-HR之代码创建临时表并插入数据 完整功能之员工职业信息变更报表
目的示例1: 制作员工职业信息报表[S-HR系统的报表其实就是列表o.0,醉了] EcirrWithPP.js shr.defineClass("shr.custom.EcirrWithPP ...
- script标签属性sync和defer
<script src="a.js" defer></script> 加了defer属性script标签的页面,运行流程如下: 1.浏览器开始解析HTM ...
- spring 中属性scope 的prototype(有状态)和singleton(无状态)
默认情况下,从bean工厂所取得的实例为Singleton(bean的singleton属性) Singleton: Spring容器只存在一个共享的bean实例, 默认的配置. Prototype: ...
- The method buildSessionFactory() from the type Configuration is deprecated.SessionFactory的变化
在创建Configuration对象之后:Configuration cfg = new Configuration().configure(); 要通过Configuration创建SessionF ...
- tab下拉显示
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...
- css--小白入门篇2
一.css基础选择器 html负责结构,css负责样式,js负责行为. css写在head标签里面,容器style标签. 先写选择器,然后写大括号,大括号里面是样式. 1 <style type ...
- 洛谷——P2261 [CQOI2007]余数求和
P2261 [CQOI2007]余数求和 关键在于化简公式,题目所求$\sum_{i=1}^{n}k\mod i$ 简化式子,也就是$\sum_{i=1}^{n}(k-\frac{k}{i}\time ...