KK's Steel bestcoder round 71 hdu 5620(裴波那契)

2 篇文章 0 订阅

Problem Description
Our lovely KK has a difficult mathematical problem:he has a N\left( 1\leq N\leq {10}^{18}\right)N(1≤N≤10
​18
​​ ) 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\left( 1\leq T\leq 10\right)T(1≤T≤10), which indicates the number of test cases.

Each test case contains one line including a integer N\left( 1\leq N\leq {10}^{18}\right)N(1≤N≤10
​18
​​ ),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.

6->1 2 3
11->1 2 3 5
19->1 2 3 5 8
。。。。。
很容易看出来是一个裴波那契数列,求出每个刚能切成n段的长度预处理即可。

上代码,查找时都没用二分了,因为这题单个数据量不到100,也只有10组测试数据:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long int ll;
ll a[100];
ll sum[100];
void init()
{
ll x=2,y=1,z;
int cnt=0;
sum[0]=3;
while(cnt<83)
{
z=x+y;
cnt++;
a[cnt]=z;
sum[cnt]=sum[cnt-1]+z;
y=x;
x=z;
}
}
int main()
{
init();
int T;
scanf("%d",&T);
while(T--)
{
ll n;
scanf("%I64d",&n);
if(n<=2)
{
cout<<1<<endl;
continue;
}
if(n<=5)
{
cout<<2<<endl;
continue;
}
int pos;
for(int i=1;i<=83;i++)
{
if(n==sum[i])
{
pos=i;
break;
}
else if(n<sum[i])
{
pos=i-1;
break;
}
}
cout<<pos+2<<endl;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值