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 cgp2001 at 2008-06-13 23:08:31 on Problem 1207
我开这么大的内存,结果过了,还只用2M.

Memory: 2624K  Time: 0MS 
Language: C++  Result: Accepted 

#include "stdio.h"
int len[50000001];
int f(int v);
int main(int argc, char* argv[])
{
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF)
	{
		int x=a<b?a:b;
		int y=a>b?a:b;
		int maxlen=f(x),i;
		for(i=x+1;i<=y;++i)
			if(maxlen<f(i))
				maxlen=f(i);
		printf("%d %d %d\n",a,b,maxlen);

	}
	return 0;
}
int f(int v)
{
	if(len[v]) return len[v];
	if(v==1)
		len[v]=1;
	else if(v%2)
		len[v]=f(v*3+1)+1;
	else
		len[v]=f(v/2)+1;
	return len[v];
}



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