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

暴力能过,时间只要0ms,内存为284K

Posted by luchenqun at 2010-07-29 16:39:36 on Problem 1207
#include<iostream>
using namespace std;
int array[10008]={0};
int f(int n)
{
	if(n%2==0)
		return f(n/2)+1;
	if(n%2!=0&&n>1)
		return f(3*n+1)+1;
	if(n==1)
		return 1;
}
int main()
{
	int i,a,b,m,n;
	for(i=1;i<=10000;i++)
		array[i]=f(i);
	while(cin>>m>>n)
	{
		a=m<n?m:n;
		b=m>n?m:n;
		int max=0;
		for(i=a;i<=b;i++)
			if(array[i]>max)
				max=array[i];
			cout<<m<<" "<<n<<" "<<max<<endl;
	}

		return 0;
}

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