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 Lighting at 2006-05-05 17:35:54 on Problem 1207
In Reply To:帮忙看看为什么总是Output Limit Exceed吧 Posted by:90303125 at 2004-01-03 11:19:12
#include <stdio.h>

unsigned long getl(int n)
{
	unsigned long result=0;
	unsigned long r=n;
	while(r>1)
	{
		if(r%2==0)
		{
			r/=2;
			result++;
			continue;
		}
		if(r%2==1)
		{
			r=r*3+1;
			result++;
			continue;
		}
	}
	return(result);
}

void main()
{
	int i,j,k;
	int m,n;
	unsigned long max=0,temp;
	while(scanf("%d %d",&i,&j)!=EOF)
	{
		max=0;
		m=i>j?j:i;
		n=i>j?i:j;
		for(k=m;k<=n;k++)
		{
			temp=getl(k);
			if(temp>max)
				max=temp;
		}
		printf("%d %d %ld\n",i,j,max+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