Ancient Go
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 cell board, the chess can be put on the intersection of the board lines, so there are 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,
.
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.
represents a cell with black chess which owned by Yu Zhou.
represents a cell with white chess which owned by Su Lu.
Output
For each test case, output one line containing
Case #x: y
, where
is the test case number (starting from 1) and
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
Here is the rules for ancient go they were playing:
The game is played on a cell board, the chess can be put on the intersection of the board lines, so there are 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..... ........oSample Output
Case #1: Can kill in one move!!!
Case #2: Can not kill in one move!!!
Hint
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.
题意:放一个x,判断能不能将o吃掉,o被吃掉的条件为o不与任何一个“.”接触。
思路:搜索
AC代码:
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<string>
- #include<algorithm>
- #include<cmath>
- #include<utility>
- #include<set>
- #include<vector>
- #include<map>
- #include<queue>
- #include<stack>
- #define maxn 1010
- #define INF 0x3f3f3f3f
- #define LL long long
- #define ULL unsigned long long
- #define E 1e-8
- #define mod 1000000007
- #define P pair<int,int>
- using namespace std;
- struct node
- {
- int x,y;
- }f[100];
- int t;
- int ff[][2]={-1,0,1,0,0,-1,0,1};
- char a[20][20];
- int ans;
- bool vis[20][20];
- bool check(int x,int y)
- {
- if(x>=0&&x<9&&y>=0&&y<9) return true;
- else return false;
- }
- int dfs(int x,int y)
- {
- int sum=0;
- for(int i=0;i<4;i++){
- int X=x+ff[i][0];
- int Y=y+ff[i][1];
- if(check(X,Y)&&!vis[X][Y]){
- if(a[X][Y]=='.'){
- vis[X][Y]=true;
- sum++;
- }
- else if(a[X][Y]=='o'){
- vis[X][Y]=true;
- sum+=dfs(X,Y);
- }
- }
- }
- return sum;
- }
- int main()
- {
- scanf("%d",&t);
- int cas=0;
- while(t--){
- ans=0;
- bool flag=false;
- for(int i=0;i<9;i++){
- scanf("%s",a[i]);
- for(int j=0;j<9;j++){
- if(a[i][j]=='o'){
- f[ans].x=i;
- f[ans++].y=j;
- }
- }
- }
- printf("Case #%d: ",++cas);
- for(int i=0;i<ans;i++){
- memset(vis,false,sizeof(vis));
- vis[f[i].x][f[i].y]=true;
- int x=dfs(f[i].x,f[i].y);
- if(x==1){
- //cout<<f[i].x<<" "<<f[i].y<<endl;
- printf("Can kill in one move!!!\n");
- flag=true;
- break;
- }
- }
- if(!flag){
- printf("Can not kill in one move!!!\n");
- }
- }
- return 0;
- }