hdu5546 Ancient Go DFS搜索 国庆咸鱼

kyoma · · 842 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。


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;
}








有疑问加站长微信联系(非本文作者)

本文来自:CSDN博客

感谢作者:kyoma

查看原文:hdu5546 Ancient Go DFS搜索 国庆咸鱼

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

842 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传