Ancient Go

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 8×88×8 cell board, the chess can be put on the intersection of the board lines, so there are 9×99×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(1≤T≤100). TT 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′′x′ represents a cell with black chess which owned by Yu Zhou. ′o′′o′represents a cell with white chess which owned by Su Lu.

Output

For each test case, output one line containingCase #x: y, where xx is the test case number (starting from 1) and yy 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!!!

        
  

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就被围住了,o就死了。所以

就是找到o 判断周围有几个.  如果只有一个.的话 那就能can  如果不是,那就can  not

 测试案例一倒着看

竟然掉进数组的坑了

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
char map[15][15];
int vis[15][15];//访问标记
int ans;
int use[15][15];

int mov[][2]={0,1,0,-1,1,0,-1,0};//一样 
//int mov[][2]={{0,1},{0,-1},{1,0},{-1,0}};//四个方向
//int mov[][2]={(0,1),(0,-1),(1,0),(-1,0)}; //错误 
void dfs(int x,int y){
	//mov[][2]默认从0开始 
	for(int i=0;i<4;++i){
		int xx=x+mov[i][0];//横坐标移动 
		int yy=y+mov[i][1];//纵坐标移动
		if(xx>=1&&xx<=9&&yy>=1&&yy<=9&&map[xx][yy]=='.'&&!use[xx][yy]){
		//所搜索的点在边界内,并且是'.',还没有被用过 
		use[xx][yy]=1;//将空位置放置上棋子 
		ans++;	
		} 
	}
	//找到o 判断周围有几个.  如果只有一个.的话 那就能can  如果不是,那就can  not
	for(int j=0;j<4;++j){
		int xx=x+mov[j][0];
		int yy=y+mov[j][1];
		if(xx>=1&&xx<=9&&yy>=1&&yy<=9&&map[xx][yy]=='o'&&!vis[xx][yy]){
			//所搜索的点在边界内,并且是'O',还没有被访问
			vis[xx][yy]=1;//访问标记 
			dfs(xx,yy); //继续搜索 
		}	
	} 
}
int main(){
	int n,k=1,flag;
	cin>>n;
	while(n--){
		for(int i=1;i<=9;++i){
			for(int j=1;j<=9;++j){
				cin>>map[i][j];//输入时按字符串输入
			}
		}
		//初始化操作 标记 访问标记 
		flag=0;
		memset(vis,0,sizeof(vis));
		for(int i=1;i<=9;++i){
			for(int j=1;j<=9;++j){
			if(map[i][j]=='o'&&!vis[i][j]){
				//未被访问
				ans=0; 
				vis[i][j]=1;
				memset(use,0,sizeof(use));
				dfs(i,j);
				if(ans==1){
					flag=1;
					break;
				}
			}	
			}
			if(flag)break;
		} 
		if(flag){
			printf("Case #%d: Can kill in one move!!!\n",k++);
		}
		else{
			printf("Case #%d: Can not kill in one move!!!\n",k++);
		}
	}
	return 0;
} //lvalue required as left operand  判断是 == 

猜你喜欢

转载自blog.csdn.net/dujuancao11/article/details/81143457
今日推荐