【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; }
标签:洪水,++,xyz,cin,int,newx,codevs3411,1010 来源: https://www.cnblogs.com/gwj13114/p/15555972.html