2015ccpc——G
来源:互联网 发布:软件质量指标 编辑:程序博客网 时间:2024/06/10 19:50
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×88×8 cell board, the chess can be put on the intersection of the board lines, so there are 9×99×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(1≤T≤100). TT 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′′x′ represents a cell with black chess which owned by Yu Zhou. ′o′′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 xx is the test case number (starting from 1) and yy 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
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!!!
Here is the rules for ancient go they were playing:
⋅⋅The game is played on a 8×88×8 cell board, the chess can be put on the intersection of the board lines, so there are 9×99×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(1≤T≤100). TT 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′′x′ represents a cell with black chess which owned by Yu Zhou. ′o′′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 xx is the test case number (starting from 1) and yy 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
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!!!
题意:再放一个x,问能不能将o包围起来。
解题思路:判断是一个节点被围起来,还是一个快被围起来。单个节点比较好判断,只需要判断o的上下左右'.'的个数,个数为1,则表示可以成功。
对于块,就当成联通块去处理,看这个联通块的'.'的个数。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;char maze[10][10];int vis1[10][10],vis2[10][10];int dx[]={1,-1,0,0},dy[]={0,0,1,-1};int cnt;bool check1(int x,int y){ if(x<0||x>=9||y<0||y>=9||maze[x][y]!='.') return false; return true;}bool check2(int x,int y){ if(x<0||x>=9||y<0||y>=9||maze[x][y]!='o') return false; return true;}void dfs(int x,int y){ int x1,y1; for(int i=0;i<4;i++)//处理单个节点 { x1=x+dx[i]; y1=y+dy[i]; if(check1(x1,y1)&&!vis2[x1][y1]) { vis2[x1][y1]=1; cnt++; } } for(int i=0;i<4;i++)//处理联通块 { x1=x+dx[i]; y1=y+dy[i]; if(check2(x1,y1)&&!vis1[x1][y1]) { vis1[x1][y1]=1; dfs(x1,y1); } }}int main(){ int t,cas=1,flag; scanf("%d",&t); while(t--) { flag=0; for(int i=0;i<9;i++) scanf("%s",maze[i]); memset(vis1,0,sizeof(vis1)); memset(vis2,0,sizeof(vis2)); for(int i=0;i<9;i++) { for(int j=0;j<9;j++) { if(maze[i][j]=='o'&&!vis1[i][j]) { vis1[i][j]=1; memset(vis2,0,sizeof(vis2)); cnt=0; dfs(i,j); if(cnt==1)//表明只有一个地方恰好可以放x。 { flag=1; } if(flag) break; } } if(flag) break; } 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;}
阅读全文
0 0
- 2015ccpc——G
- 2015 ccpc G题解
- 2015ccpc G
- 2015ccpc——H
- 2015 南阳 CCPC G.Ancient Go
- 2015 CCPC G题 【DFS 暴力】
- CCPC长春 G Instability
- CCPC-CDOJ-1221-G题
- 2017 CCPC 秦皇岛 G题
- 2017 CCPC 秦皇岛 G题
- ccpc东北四——重现赛
- 南阳CCPC G题 Ancient Go
- CCPC 2015 A题
- 2015 CCPC D题
- 2015 CCPC Ancient Go
- 2015 ICPC && CCPC - 小记
- 2015南阳CCPC Hdu5547
- CCPC 2015 部分题解
- java 实现递归查找数组中的重复数字
- HTML_JavaScript
- 解决长串不能自动换行的问题和td中汉字自动换行 && CSS强制不换行
- HB 官方新版 1-100 任务升级脚本
- 关于eclipse中properties文件中文提交到SVN后变成unicode编码
- 2015ccpc——G
- 触发器有父子关系时的使用
- 概率统计——贝叶斯定理
- Python爬虫——实战四:爬取亚马逊的商品价格
- 网络流之最大流算法——EK算法(通俗讲解)
- Spring NoSuchBeanDefinitionException原因分析
- 欢迎使用CSDN-markdown编辑器
- 基于Jquery实现的手风琴
- 顺序表-增(插入)