您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: