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 xiaoyuanwang at 2007-05-10 11:06:36 on Problem 1207
我用个递归打表
然后再搜索MAX就搞定了,用时15MS
先把2的幂次的次数保存起来,
for(i=1;i*2<=100000;i=i*2)
	{
		result[i*2]=result[i]+1;
	}
再打表
int get_step(int *r,int n)
{
	int step=1;
	if(n%2)
	{
		n=n*3+1;
		while(n>100000)
		{
			step++;
			if(n%2)n=n*3+1;
			else n=n/2;
		}
		
		if(r[n])return step+r[n];
		else return step+get_step(r,n);

	}
	else 
	{
		n=n/2;
		if(r[n])return step+r[n];
		else return step+get_step(r,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