HDU5546 Ancient Go(深搜DFS)(2015CCPC)
来源:互联网 发布:c语言的编程环境 编辑:程序博客网 时间:2024/05/21 19:25
题目:
Ancient Go
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2263 Accepted Submission(s): 703
Problem 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.
Here is the rules for ancient go they were playing:
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
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!!!HintIn 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
Recommend
wange2014 | We have carefully selected several similar problems for you: 6022 6021 6020 6019 6018
简单地说一下题意,周瑜和鲁肃下围棋,周瑜用的是‘X’,鲁肃用的是‘O’,现在该周瑜走了,问的是周瑜能不能再这一步吃掉鲁肃的至少一枚棋子(完全包围),原来的想法是把所有的o点记录下来,然后搜他附近有几个x,但是最后一直WA,最后换了种方法,找点每一个'.',然后放置棋子,看能不能吃,每走一步把走过的o标记为#
直接看代码吧
代码:
#include <cstdio>#include <cstring>#include <cctype>#include <string>#include <set>#include <iostream>#include <stack>#include <cmath>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define mod 10000007#define debug() puts("what the fuck!!!")#define N 200200#define M 1000000#define ll long longusing namespace std;char map[15][15],mp[15][15];int go[4][2]= {0,1,1,0,-1,0,0,-1};int flag;void dfs(int x,int y){ for(int i=0; i<4; i++) { int xx=x+go[i][0]; int yy=y+go[i][1]; if(xx>=0&&xx<9&&yy>=0&&yy<9&&mp[xx][yy]=='.') flag=1; if(xx>=0&&xx<9&&yy>=0&&yy<9&&mp[xx][yy]=='o') { mp[xx][yy]='#'; dfs(xx,yy); } }}int jc(){ for(int i=0; i<9; i++) { for(int j=0; j<9; j++) { if(mp[i][j]=='o') { mp[i][j]='#'; flag=0; dfs(i,j); if(flag==0)return 1; } } } return 0;}int main(){ int t,q=1; scanf("%d",&t); while(t--) { int folg=0; for(int i=0; i<9; i++) scanf("%s",map[i]); for(int i=0; i<9; i++) { for(int j=0; j<9; j++) { if(map[i][j]=='.') { map[i][j]='x'; memcpy(mp,map,sizeof(map)); if(jc())folg=1; map[i][j]='.'; } } } if(folg) printf("Case #%d: Can kill in one move!!!\n",q++); else printf("Case #%d: Can not kill in one move!!!\n",q++); } return 0;}
0 0
- HDU5546 Ancient Go(深搜DFS)(2015CCPC)
- HDU5546 Ancient Go(DFS)
- HDU5546 Ancient Go DFS
- 【HDU5546 2015 CCPC 南阳国赛G】【DFS】Ancient Go 棋盘围杀 优化写法O(n^2)
- Ancient Go【ccpc dfs】
- hdu5546 Ancient Go(bfs)
- hdu5546 Ancient Go DFS搜索 国庆咸鱼
- 2015 南阳 CCPC hdu 5546 Ancient Go(DFS,暴力)
- 2015 CCPC Ancient Go
- HDU5546-Ancient Go
- hdu 5546 Ancient Go(2016ccpc) 暴力DFS
- 2015 南阳理工CCPC Ancient Go
- 2015 南阳 CCPC G.Ancient Go
- ccpc Ancient Go(dfs求连通块周围'.'的数目)
- hdu5546 Ancient Go 简单深搜
- HDU 5546 Ancient Go(DFS)
- HDU 5546 Ancient Go (dfs)
- HDU~5546 Ancient Go(暴力dfs)
- 线性表续——双向、循环链表
- Spring面试,IoC和AOP的理解
- 时间序列模型
- 错误:java.lang.IllegalArgumentException: Service not registered
- code[vs] 1154能量项链(成环的区间dp)
- HDU5546 Ancient Go(深搜DFS)(2015CCPC)
- L2-021. 点赞狂魔
- bzoj4843
- VR系列——Oculus Rift 介绍指南:四、Oculus Rift的硬件设置
- 找出数组中出现次数最多的数字&找出数组中只出现一次的数字
- DOM4J XML解析
- POJ 2411 Mondriaan's Dream 状态压缩
- 为bookStore添加权限【动态代理和注解】
- fl2440 内核移植