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

哪位牛哥哥帮我看看呀,为什么所有的数据能过,也避免了陷阱,还是wrong answer!!

Posted by ace_killer at 2009-04-11 14:17:09 on Problem 1207
#include<stdio.h>
//对每一个数求它的次数
int f(int m){
	int count=0;
	while(m!=1)
	{
		if(m%2!=0)
			m=3*m+1;
		else
			m/=2;
		count++;
	}
	return count;
}
//在m、n之间每个数寻找最多的次数
int fb(int m,int n)
{	
	int b[100000],i,max;
	static int j=0;
	for(i=m;i<=n;i++)
	{
		b[j++]=f(i);
	}
	max=b[0];
	for(i=0;i<j;i++){
		if(b[i]>max)
			max=b[i];
	}
	return max;
}
void main(){
	int m[1000][2],i=0,count=0,temp;
	for(i=0;scanf("%d%d",&m[i][0],&m[i][1])!=EOF;i++)
		count++;
	for(i=0;i<count;i++)
		if(m[i][0]>0&&m[i][0]<10010)
			if(m[i][1]>0&&m[i][1]<10010)
			{	printf("%d %d ",m[i][0],m[i][1]);
				if(m[i][0]>m[i][1])
				{
					temp=m[i][0];
					m[i][0]=m[i][1];
					m[i][1]=temp;
				}
				printf("%d\n",fb(m[i][0],m[i][1])+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