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 sangyezi at 2005-03-26 11:41:48 on Problem 1088
总是1015ms,是不是到这个时间就不运行了?
我的在机子上运行的挺好的,而且每个点只算一次就可以了,不应该会超时啊


Memory:80K  Time:1015MS
Language:C++  Result:Time Limit Exceed

Source 

#include <iostream.h>
enum error {illegal};
int search(int row,int line,int **height,int R,int C)
{
	 //[row][line]为当前所在的格子
	int g,h,sum,k=0,summary=1;
	int direction[4][2]={0,1,1,0,0,-1,-1,0};
	while (k<=3)
	{
		sum=0;
		g=row+direction[k][0];
		h=line+direction[k][1];//[g][h]为试探的下一个格子,从东侧顺时针试探
		if ( g>=0 && g<R  && h>=0 && h<C) 
			if (height[g][h]<height[row][line])
			{
				if (height[g][h]>8849)
				{
					height[g][h]=search(g,h,height,R,C);
					sum=height[g][h]+1;
				}
				else sum=height[g][h]+1;
			}
		if (sum>summary)
			summary=sum;
		k++;
	}
    return summary;
}
int main()
{
	int i,j,R,C;
	int total=0;
	int summary=0;
	cin>>R>>C;
	if (R<1 || R>100 || C<1 || C>100) 
		return illegal;
    int **height=new int *[R];
	for (i=0;i<R;i++)
		height[i]=new int [C];

	for (i=0;i<R;i++)
		for (j=0;j<C;j++)
		{
			cin>>height[i][j];
			height[i][j]=height[i][j]+10000;
		}
	for (i=0;i<R;i++)
		for (j=0;j<C;j++)
		{
			summary=search(i,j,height,R,C);
            if (total<summary)
				total=summary;
		}
	cout<<total<<endl;
	return 1;
} 

非常感谢!

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