HDU-5546(简单DFS)
来源:互联网 发布:c# python 编辑:程序博客网 时间:2024/06/06 01:04
Ancient Go
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2301 Accepted Submission(s): 718
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.
题解:
题目大意:
x和o分别代表两个人的棋,游戏规则就是围棋,问x再下一个棋能不能杀死o的至少一个棋子(被杀死的条件就是o完全被x包围,在x的包围圈里已经一个棋都下不了了)。
我的思路:一道简单的dfs,就是找到一个o棋子,如果他旁边只有一个位置可以下,那么就可以被杀死。如果是有好多个连起来的o棋子,就判断这些连起来所有的边界有多少个可以下的位置如果只有一个,就可以被杀死。
下面附上代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char mp[12][12];int temp, vis[12][12], vis2[12][12];int fx[4][2] = {1,0,-1,0,0,1,0,-1};void dfs(int x, int y){// if(temp >= 2) return; for(int i = 0; i < 4; i++) { int nx = x+fx[i][0], ny = y+fx[i][1]; if(mp[nx][ny] == '.' && !vis2[nx][ny]) { temp++; vis2[nx][ny] = 1; } if(mp[nx][ny] == 'o' && !vis[nx][ny]) { vis[nx][ny] = 1; dfs(nx, ny); } }}int main(){ int T, num = 1; scanf("%d", &T); while(T--) { int flag = 0; for(int i = 0; i < 12; i++) for(int j = 0; j < 12; j++) mp[i][j] = 'x'; memset(vis, 0, sizeof(vis)); for(int i = 1; i <= 9; i++) scanf("%s", mp[i]+1); for(int i = 1; i <= 9; i++) { for(int j = 1; j <= 9; j++) { if(mp[i][j] == 'o' && !vis[i][j]) { memset(vis2, 0, sizeof(vis2)); vis[i][j] = 1; temp = 0; dfs(i, j); if(temp<=1) // 这个一定是小于等于1,小于1的时候是x不需要下棋o已经被包围了。 { flag = 1; break; } } } if(flag) break; } if(flag) printf("Case #%d: Can kill in one move!!!\n", num++); else printf("Case #%d: Can not kill in one move!!!\n", num++); } return 0;}
0 0
- HDU-5546(简单DFS)
- hdu 2952 Counting Sheep(简单dfs)
- HDU 5305 Friends(简单DFS)
- hdu 1175 连连看 (简单DFS)
- hdu 1241 简单 搜索DFS (深搜)
- hdu N皇后问题 (简单DFS)
- HDU-1213(简单DFS)
- hdu 2660 简单 dfs
- hdu 3274 简单 dfs
- hdu 3290 (简单dfs)
- hdu 1241 简单dfs
- 搜索--HDU简单DFS
- HDU 1181(简单dfs)
- HDU--1241 简单DFS
- HDU 1016 超简单DFS
- HDU 3368 Reversi (简单dfs)
- HDU/HDOJ 1016 简单dfs
- HDU 1241 简单的DFS
- UVALive
- CAN与CANOpen(二)
- Ajax什么时候进入success和error
- 欢迎使用CSDN-markdown编辑器
- 算法学习之二:归并排序
- HDU-5546(简单DFS)
- ASP .NET MVC ORM概述
- C# 接口
- Hive函数大全
- 配置sharepoint 爬网遇到的坑
- RecyclerView的深入了解
- 如何在神箭手上快速开发爬虫——第二课 如何爬取JS动态生成的数据【豌豆荚游戏排行榜】
- 接收消息
- 数组划分--lintcode