HDU Oil Deposits

来源:互联网 发布:xshell linux版 编辑:程序博客网 时间:2024/04/30 04:07

简单搜索

#include <iostream>#include <cstdio>#include <queue>#include <cstring>#include <cmath>#include <vector>#include <set>#include <stack>#include <algorithm>//#include "myAlgorithm.h"#define MAX 105#define INF (1e8 + 5)#define eps 1e-8#define Rep(s, e) for( int i = s; i <= e; i++)#define Cep(e, s) for( int i = e; i >= s; i --)using namespace std;int n, m;char str[MAX][MAX];int ans = 0;int dir[][2] = {{ -1, 0},{1, 0},{0, -1}, {0, 1}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}};///eight directionstruct Point{    int y , x;};void bfs(Point start){    ans ++;    queue<Point>q;    q.push(start);    str[start.y][start.x] = '*';//set wall;    Point tt, temp;    while(!q.empty()){        temp = q.front(); q.pop();        Rep(0, 7){            int I = temp.y + dir[i][0], J = temp.x + dir[i][1];            if(I > -1 && J > -1 && I < m && J < n && str[I][J] == '@'){                str[I][J] = '*';// set wall;                tt.y = I; tt.x  = J;                q.push(tt);            }        }    }}void solve(){    Point start;    ans = 0;    Rep(0, m - 1){        for(int j = 0; j < n;j++){            if(str[i][j] == '@'){                start.y = i;  start.x = j;                bfs(start);            }        }    }    cout<<ans<<endl;}int main() {    //freopen("in.tx0t", "w", stdout);    while(cin>>m>>n, m){        getchar();        Rep(0, m - 1){            cin>>str[i];        }///end input        solve();    }    return 0;}/**/


 

原创粉丝点击