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 |
985ms 差一点就没过去!汗!贴一下,大家见笑了!#include<iostream> #include<stdlib.h> using namespace std; int m,n; int a[110][110]; int c[110][110]; struct point { int value; int x; int y; }; int fun(int i,int j) { int sum1=0,sum2=0,sum3=0,sum4=0; int max1,max2,max; if(a[i][j]<=a[i-1][j]&&a[i][j]<=a[i+1][j]&&a[i][j]<=a[i][j-1]&&a[i][j]<=a[i][j+1]) return 1; if(i>1&&a[i][j]>a[i-1][j]) { if(c[i-1][j]==-1) c[i-1][j]=fun(i-1,j); } if(i<m&&a[i][j]>a[i+1][j]) { if(c[i+1][j]==-1) c[i+1][j]=fun(i+1,j);} if(j>1&&a[i][j]>a[i][j-1]) { if(c[i][j-1]==-1) c[i][j-1]=fun(i,j-1); } if(j<n&&a[i][j]>a[i][j+1]){ if(c[i][j+1]==-1) c[i][j+1]=fun(i,j+1);} if(c[i-1][j]>c[i+1][j]) max1=c[i-1][j]; else max1=c[i+1][j]; if(c[i][j-1]>c[i][j+1]) max2=c[i][j-1]; else max2=c[i][j+1]; if(max1>max2) max=max1; else max=max2; return max+1; } int main() { cin>>m>>n; int i,j; memset(c,-1,sizeof(c)); if(m==0||n==0) {cout<<"1"<<endl; } else{ point b[11000]; int l=0; for(i=0;i<=m+1;i++) {a[0][i]=1100000000; a[m+1][i]=1100000000; } for(i=0;i<=n+1;i++) { a[i][0]=1100000000; a[i][n+1]=1100000000; } for(i=1;i<=m;i++) for(j=1;j<=n;j++) {cin>>a[i][j]; } for(i=1;i<=m;i++) for(j=1;j<=n;j++) {if(a[i][j]==-1) continue; b[l].value=fun(i,j); b[l].x=i; b[l].y=j; l++; memset(c,-1,sizeof(c)); } int flag=0; for(i=0;i<l;i++) {if(b[flag].value<b[i].value) flag=i; } cout<<b[flag].value<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator