Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 大神求解

Posted by 2801748509 at 2018-02-26 16:42:43 on Problem 1088
```#include<iostream>
#include<algorithm>
using namespace std;

int length,wide,map_high[3002][3002],hd,tl,q[3000002][4],by,nx,ny;
int dx[5]={-1,0,0,1},dy[5]={0,-1,1,0},res[3002][3002],bx,maxx;

void bfs(int x,int y){
hd=0;tl=1;q[1][0]=x;q[1][1]=y;res[x][y]=1;
while(hd^tl){
hd++;int a[5][3]={0};
for(int i=0;i<4;i++){
nx=q[hd][0]+dx[i];
ny=q[hd][1]+dy[i];
if(nx<1||nx>length||ny<1||ny>wide||res[nx][ny]||map_high[nx][ny]>map_high[q[hd][0]][q[hd][1]])continue;
a[i][2]=map_high[nx][ny];a[i][0]=nx;a[i][1]=ny;
}
int maxh=a[1][2],cx=a[1][0],cy=a[1][1];
for(int i=2;i<=4;i++)
if(a[i][2]>maxh){maxh=a[i][2];cx=a[i][0];cy=a[i][1];}
tl++;res[cx][cy]=1;q[tl][0]=maxh;q[tl][1]=cy;q[tl][0]=cx;q[tl][2]=q[hd][2]+1;
if(maxh==0)return;
}
}
int main(){
cin>>length>>wide;
for(int i=1;i<=length;i++)
for(int j=1;j<=wide;j++)
cin>>map_high[i][j];
maxx=map_high[1][1];bx=1;by=1;
for(int i=1;i<=length;i++)
for(int j=1;j<=wide;j++)
if(map_high[i][j]>maxx){
maxx=map_high[i][j];
bx=i;by=j;
}
bfs(bx,by);
cout<<q[tl][2];
return 0;
}```

Followed by: