| ||||||||||
| 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 | |||||||||
时间复杂度不降低,就算改对了也只能超时In Reply To:代码已经改成如下的了,没有超时,还是错误啊 Posted by:clwey at 2006-03-21 16:31:44 best 初始化应赋值1
或者,把if(best<m[i][j])best=m[i][j];放到else外面
> #include"stdio.h"
> #include"stdlib.h"
> int cmp ( const void *a , const void *b )
> {
> return *(int *)a - *(int *)b;
> }
> main(){
> int a,b,c[100][100],i,j,k[10000],x,m[100][100],n[4],best;
> while(scanf("%d %d",&a,&b)==2){
> best=0;
> for(i=0;i<a;i++)
> for(j=0;j<b;j++){
> c[i][j]=0;
> m[i][j]=0;
> }
> for(i=0;i<a;i++)
> for(j=0;j<b;j++){
> scanf("%d",&c[i][j]);
> k[b*i+j]=c[i][j];
> }
> qsort(k,a*b,sizeof(k[0]),cmp);
> for(x=0;x<a*b;x++)
> for(i=0;i<a;i++)
> for(j=0;j<b;j++)
> if(c[i][j]==k[x]){
> if(c[i][j]==k[0]) m[i][j]=1;
> else{
> if(j>=1&&c[i][j]>c[i][j-1]) n[0]=m[i][j-1];
> else n[0]=0;
> if(j+1<b&&c[i][j]>c[i][j+1]) n[1]=m[i][j+1];
> else n[1]=0;
> if(i>=1&&c[i][j]>c[i-1][j]) n[2]=m[i-1][j];
> else n[2]=0;
> if(i+1<a&&c[i][j]>c[i+1][j]) n[3]=m[i+1][j];
> else n[3]=0;
> qsort(n,4,sizeof(n[0]),cmp);
> m[i][j]=n[3]+1;
> if(best<m[i][j]) best=m[i][j];
> }
> }
> printf("%d\n",best);
> }
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator