题意:一个9*9的棋盘,判断能否把接下来的一个x,放到地图中的一个空白位置上。 使得出现一个联通块内的o,找不到任何一个可以扩展的联通块位置'.' 思路:枚举o周围的x放置,如果周围可放置数为1,表示成功,注意重复记录,所以用两个数组个标记
要注意的是!!!! 枚举‘o’联通块周围的‘.’空地时,要判重,不然要wrong,,哎哎哎,不够细心
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:
⋅ 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.
2 .......xo ......... ......... ..x...... .xox....x .o.o...xo ..o...... .....xxxo ....xooo. ......ox. .......o. ...o..... ..o.o.... ...o..... ......... .......o. ...x..... ........o
Case #1: Can kill in one move!!!
Case #2: Can not kill in one move!!!
In 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.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
char a[11][11];
int vis[11][11],vis1[11][11];
const int n = 9;
int flag;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
void check(int x,int y)
{
int i,j;
for(i=0;i<4;i++) {
int xx = x+dx[i];
int yy = y+dy[i];
if(xx<0||xx>=n||yy<0||yy>=n||vis1[xx][yy]) continue;
if(a[xx][yy]=='.') flag++,vis1[xx][yy]=1;
}
}
void dfs(int x,int y)
{
int i,j;
int xx,yy;
check(x,y);
for(i=0;i<4;i++) {
xx=x+dx[i];
yy=y+dy[i];
if(xx<0||xx>=n||yy<0||yy>=n||vis[xx][yy]) continue;
if(a[xx][yy]!='o') continue;
vis[xx][yy]=1;
dfs(xx,yy);
}
}
int main()
{
int T,i,j;
scanf("%d",&T);
for(int _=1;_<=T;_++) {
memset(vis,0,sizeof(vis));
for(i=0;i<n;i++) scanf("%s",a[i]);
for(i=0;i<n;i++) {
for(j=0;j<n;j++) {
flag=0;
if(a[i][j]=='o' && vis[i][j]==0) {
vis[i][j]=1;
memset(vis1,0,sizeof(vis1));
dfs(i,j);
if(flag==1) break;
}
}
if(flag==1) break;
}
printf("Case #%d: ",_);
if(flag==1) printf("Can kill in one move!!!\n");
else printf("Can not kill in one move!!!\n");
}
return 0;
}