HDU 5620 KK's Steel(找规律,斐波那契数列的应用)

KK's Steel

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 675    Accepted Submission(s): 313


Problem Description
Our lovely KK has a difficult mathematical problem:he has a N(1N1018) meters steel,he will cut it into steels as many as possible,and he doesn't want any two of them be the same length or any three of them can form a triangle.
 

Input
The first line of the input file contains an integer T(1T10) , which indicates the number of test cases.

Each test case contains one line including a integer N(1N1018) ,indicating the length of the steel.
 

Output
For each test case, output one line, an integer represent the maxiumum number of steels he can cut it into.
 

Sample Input
  
  
1 6
 

Sample Output
  
  
3
Hint
1+2+3=6 but 1+2=3 They are all different and cannot make a triangle.
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5649  5648  5647  5646  5645 
 所截取的钢管长度不能相等,并且任意三根不能围成三角形,所以当a1+a2=a3时就不能满足,斐波那契数列的应用,不过写时没想到,一直想着满足不能围成三角形的条件
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
__int64 a[1100000];
__int64 n;
void fun()
{
	a[1]=1;
	a[2]=2;
	for(__int64 i=3;i<1100000;i++)
	{
		a[i]=a[i-1]+a[i-2];
	}
	
}
int main()
{
	fun();
	int t;
	scanf("%d",&t);
	while(t--)
	{
		
		scanf("%I64d",&n);
		__int64 i;
		__int64 sum=0;
		for(i=1;i<1100000;i++)
		{
			sum+=a[i];
			if(sum>n)
			{
				break;
			}
		}
		if(n==1||n==2)//这里要判断一下 
		{
			printf("1\n");
			continue;
		}
		
		 printf("%I64d\n",i-1);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值