首页 > 其他分享 >【codevs3411】洪水

【codevs3411】洪水

时间:2023-02-08 12:38:03浏览次数:40  
标签:newy 洪水 xyz ++ int newx codevs3411 1010


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


标签:newy,洪水,xyz,++,int,newx,codevs3411,1010
From: https://blog.51cto.com/gwj1314/6044048

相关文章