hdu5546
2016-05-05 10:30
323 查看
Ancient Go
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 799 Accepted Submission(s): 283
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.
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!!!
题意:敌我两方下围棋,给一个棋盘,我方为x,敌方为o,现在该我方走,问能不能一步杀掉敌方自少一个子,当x能把o围起来是就能吃掉被围棋子
搜索划分联通块,按照o搜索,当搜索到x时不做搜索,当搜索到o时记录所属连通块,当搜索到.时,给标记加1,即每个连通块可达.的数量等于1,时我们可以一步制胜。
ac代码:
#include <iostream>
#include <string.h>
using namespace std;
int vis[15][15];
int tot,cnt;
char mp[15][15];
int dx[4]= {0,1,0,-1};
int dy[4]= {1,0,-1,0};
void dfs(int x,int y)
{
vis[x][y]=tot;
int nx,ny;
for(int i=0; i<4; i++)
{
nx=dx[i]+x;
ny=dy[i]+y;
if(nx>=9||nx<0||ny>=9||ny<0||vis[nx][ny]==tot)
continue;
if(mp[nx][ny]=='x')continue;
if(mp[nx][ny]=='.')cnt++,vis[nx][ny]=tot;///遇到x或者.只做标记,
else
dfs(nx,ny);///只有遇到o才进行搜索
}
}
bool solve()
{
tot=0;
for(int i=0; i<9; i++)
{
for(int j=0; j<9; j++)
{
if(mp[i][j]=='o'&&!vis[i][j])
{
tot++;
cnt=0;
dfs(i,j);
if(cnt==1)
return true;
}
}
}
return false;
}
int main()
{
int t;
cin>>t;
for(int cas=1; cas<=t; cas++)
{
for(int i=0; i<9; i++)
cin>>mp[i];
memset(vis,0,sizeof(vis));
cout<<"Case #"<<cas;
if(solve())
cout<<": Can kill in one move!!!"<<endl;
else
cout<<": Can not kill in one move!!!"<<endl;
}
return 0;
}
相关文章推荐
- 类与类成员(字段和方法)的访问权限
- Win10桌面图标没了怎么办?Win10桌面快捷方式消失了解决方法
- [每日一问] 为什么做虚拟化方案设计时,要求涉及到的硬件一定要在虚拟化厂商提供的硬件兼容列表里面
- LeetCode 219: Contains Duplicate II
- Java 应用一般架构
- Retrofit的使用与深入学习(下)
- 解决ios真机调试team ID not found问题
- VR虚拟眼镜的原理是什么
- 水平方向瀑布流
- maven-jetty热部署
- mac 苹果电脑的睡眠与休眠,决待机耗电的问题,AddressBookSourceSync
- java 判断txt文件的编码格式
- 通哥运维笔记之Linux系统管理问题总结(二)
- Android platform和 API Level的区别
- Binary Tree Level Order Traversal II
- IOS中UITableViewCell使用详解
- 如何设置快捷键(File Search)
- Eclipse 快捷键 快捷输入
- win Apache服务消失或无法启动
- 通哥运维笔记之Linux系统管理问题总结(一)