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.
题意: 围棋,判断再走一步能不能吃子 思路: 9X9的棋盘dfs随便搜,对同一个连通块来说判断其周围'.'的个数是不是为1 一定要注意避免重复计数(自己想象下同一个'.'为一个连通块的不同'o'的边界) 解决方法是-给连通块编号! 编号的作用是: 对同一个'.'不用连通块可以访问多次,同一连通块只能访问一次
#include<stdio.h> #include<iostream> #include<string.h> char a[10][10]; int vis[10][10]; int dir[4][2]= {0,1,0,-1,1,0,-1,0}; int sum=0; int dfs(int s,int t) { vis[s][t]=1; for(int i=0; i<4; i++) { int xx,yy; xx=s+dir[i][0]; yy=t+dir[i][1]; if(xx>=0&&xx<9&&yy>=0&&yy<9&&!vis[xx][yy]) { if(a[xx][yy]=='o') { dfs(xx,yy); } if(a[xx][yy]=='.') { sum++; } vis[xx][yy]=1; } } return sum; } int main() { int t; scanf("%d",&t); int g=0; while(t--) { ++g; int we=0; getchar(); for(int i=0; i<9; i++) scanf("%s",a[i]); for(int i=0; i<9; i++) { for(int j=0; j<9; j++) { sum=0; if(a[i][j]=='o') { memset(vis,0,sizeof(vis)); we=dfs(i,j); if(we==1) { break; } } } if(we==1) break; } if(we==1) printf("Case #%d: Can kill in one move!!!\n",g); else printf("Case #%d: Can not kill in one move!!!\n",g); } }