【codevs3411】洪水

problem

solution

codes

#include<iostream>
#include<queue>
using namespace std;
int n, m, a[1010][1010], book[1010][1010], x, y, ans;
const int dx[] = {0,0,-1,1};
const int dy[] = {-1,1,0,0};
struct xyz{ 
    int x, y; 
    xyz(int x = 0, int y = 0):x(x),y(y){};
};
int main(){
    cin>>n>>m;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin>>a[i][j];
    cin>>x>>y;
    queue<xyz>q;
    q.push(xyz(x-1,y-1));
    while(!q.empty()){
        xyz t = q.front(); q.pop();
        for(int i = 0; i < 4; i++){
            int newx = t.x+dx[i], newy = t.y+dy[i];
            if(newx>=0 && newx<n && newy>=0 && newy<m && a[newx][newy]<=a[t.x][t.y] && !book[newx][newy])
            { q.push(xyz(newx, newy)); ans++; book[newx][newy] = 1;}
        }
    }
    cout<<n*m-ans-1;
    return 0;
}
posted @ 2018-06-03 10:32  gwj1139177410  阅读(92)  评论(0编辑  收藏  举报
选择