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。。。还以为会超时咧,水

Posted by 781778304 at 2011-08-20 09:52:58 on Problem 1207
#include<iostream>
using namespace std;
#define N 10005
int Caculate(int j)
{
	int no=1;
	while(1)
	{
		if(j==1)break;
		if(j%2==0) j/=2;
		else       j=3*j+1;
		no++;			
	}
	return no;
}
int main()
{
	int n,m;
	while(cin>>n>>m)
	{
		int j;
		int tempn=n,tempm=m;
		if(n>m){j=n;n=m;m=j;}
		int max=0;
		for(j=n;j<m+1;j++)
		{
			int temp=Caculate(j);
			max=max>temp?max:temp;
		}
		printf("%d %d %d\n",tempn,tempm,max);  //输出的时候要按照原来的顺序输出
	}
	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