Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大神求解#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: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator