#include <cstdio> #include <iostream> const int INF=0xffffff; using namespace std; struct sstep{ int i; int j; }; int main(){ int n,m; cin>>n>>m; sstep step[1000]={0}; int mmap[n+2][m+2]={0}; int mins=INF; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ int high; cin>>high; step[high].i=i; step[high].j=j; mmap[i][j]=high; if(mins>high){ mins=high; } } } int max=0; int count=0; sstep ss=step[mins];//从最低楼梯开始走 for(int i=mins+1;i<=mins+m*n+1;i++){//从台阶1开始走 int r=ss.i; int c=ss.j; int top=mmap[r-1][c]; int left=mmap[r][c-1]; int right=mmap[r][c+1]; int bottom=mmap[r+1][c]; if(top!=i&&left!=i&&right!=i&&bottom!=i){ ss=step[i]; if(max<count) max=count; count=0; } else{ count++; ss=step[i]; } } cout<<max<<endl; } |
Double click to view unformatted code.