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

Re:为什么我还是wa呢???哪位帮我看看????即使是去掉!EOF,为什么会是TLE呢??

Posted by no_sure at 2010-08-22 23:39:29 on Problem 1207
In Reply To:为什么我还是wa呢???哪位帮我看看????即使是去掉!EOF,为什么会是TLE呢?? Posted by:766826825 at 2010-08-22 20:38:56
> #include<stdio.h>
> int jud(int n)
> {
> 	int i=1;
> 	while(n!=1)
> 	{
> 		if(n%2==0)
> 			n=n/2;
> 		else 
> 			n=3*n+1;
> 		i++;
> 	}
> 	return i;
> 	
> }
> int main()
> {
> 	int i;
> 	int m,n,t;
> 	
> 	while(scanf("%ld %ld",&m,&n)!=EOF)
> 	{
> 		if(m>n)
> 		{
> 			for(i=n;i<=m;i++)
> 			{
> 				if(jud(i)>t)
> 					t=jud(i);
> 			}
> 		}
> 		for(i=m;i<=n;i++)
> 		{
> 			if(jud(i)>t)
> 				t=jud(i);
> 		}
> 		
> 		printf("%d %d %d\n",m,n,t);
> 		t=0;
> 	}
> 	return 0;
> 	
> }
可能测试方法比较特别,有人已经贴出的暴力法,是把所有的1到10000所有可能的数列长度都计算出来,由于3n+1问题,不是数字越大,数列就越长。所以m与n之间的长度需要比较每一个数字大小。
估计系统测试的是:计算不同的m,n区间,看看有没有重复的计算。但测试组较多时,已经贴出的暴力法,就存在优势了。

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