POJ1979 裸裸的深搜

RT
题目链接: POJ—1979

/**************************************
Problem: 1979       User: ChenyangDu
Memory: 212K        Time: 16MS
Language: C++       Result: Accepted
***************************************/
#include
#include
#include
#include

using namespace std;

const int map[2][4] = {1,0,0,-1,0,1,-1,0};
int n,m,in[30][30],h_x,h_y;

void input(){
    string x;
    for(int i=0;icin>>x;
        for(int j=0;jif(x[j] == '#')in[i][j] = 0;
            else if(x[j] == '@'){
                h_x = i;h_y = j;
            }
            else in[i][j] = 1;
        }
    }
}

int dfs(int x,int y){
    in[x][y] = 0;
    int a,b,ans = 1;
    for(int i=0;i<4;i++){
        a = map[0][i] + x;
        b = map[1][i] + y;
        if(a>=0 && a=0 && b1){
            ans += dfs(a,b);
        }
    }
    return ans;
}

int main(){
    //freopen("in.txt","r",stdin);
    while(scanf("%d%d",&n,&m) == 2){
        if(n == 0)break;
        input();
        cout<//fclose(stdin);
    return 0;
}

你可能感兴趣的:(深搜,POJ)