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

代码已经改成如下的了,没有超时,还是错误啊

Posted by clwey at 2006-03-21 16:31:44 on Problem 1088
In Reply To:代码已经没有错了.你的算法不对,O(n^4),超时是正常现象 Posted by:xfxyjwf at 2006-03-21 16:03:13
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator