hdu5546 Ancient Go DFS搜索 国庆咸鱼


Ancient Go

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1660    Accepted Submission(s): 528


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(1T100) 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!!!
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.
 

Source

看到数据量和样例就感觉是搜索。。。于是开始搜索。。。判断一个o块周围是否有超过两个 “ 。”,样例过了。。但是wa得很迷。。。然后自己造数据

发现原先判断是错的。。。反例如下:

.........
.........
xxx......
ooox.....
o.ox.....
xxx......
.........
.........
.........



这个本来应该是判断可以的,但我因为重复统计了。所以给判不行。然后就改成只能对o旁边的.做一次修改成x的操作,事后还原即可,小细节wa了很多。。现在要慢慢的改掉无限提交流的习惯饿了。。。。

下面代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
const int maxn=20;
char save[maxn][maxn];
int move_x[4]={0,0,1,-1};
int move_y[4]={1,-1,0,0};
//xo
int ans;
pair<int,int> maho;
void dfs(int x,int y){
    save[x][y]='x';
    int i;
    for(i=0;i<4;i++){
        int dx=x+move_x[i];
        int dy=y+move_y[i];
        if(dx>=1&&dx<=9&&dy>=1&&dy<=9){
            if(save[dx][dy]=='o'){
                dfs(dx,dy);
            }else if(save[dx][dy]=='.'){
                if(ans==0){
                    save[dx][dy]='x';
                    maho=make_pair(dx, dy);
                    ans++;
                }else{
                    ans++;
                }
            }
        }
    }
}
int main(){
    int t,i,j;
    scanf("%d",&t);
    int rnd=1;
    while(t--){
        for(i=1;i<=9;i++){
            for(j=1;j<=9;j++){
                cin>>save[i][j];
            }
        }
        bool flag=false;
        for(i=1;i<=9;i++){
            save[0][i]='x';
            save[10][i]='x';
            save[i][0]='x';
            save[i][10]='x';
        }
        for(i=1;i<=9;i++){
            for(j=1;j<=9;j++){
                if(save[i][j]=='o'){
                    ans=0;
                    dfs(i, j);
                    if(ans>0){
                        save[maho.first][maho.second]='.';
                    }
                    if(ans<=1){
                        flag=true;
                        //cout<<"haha!"<<endl;
                    }
                }
            }
        }
        if(flag){
            printf("Case #%d: Can kill in one move!!!\n",rnd);
        }else{
            printf("Case #%d: Can not kill in one move!!!\n",rnd);
        }
        rnd++;
    }
    return 0;
}







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值