HDU 5620 KK's Steel <贪心思维>

解决一个数学问题:如何将长度为N(1≤N≤10^18)的钢材切割成尽可能多的不同长度段,且任意三段不能构成三角形。通过递归寻找斐波那契数列来确定最大切割数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u

 Status

Description

Our lovely KK has a difficult mathematical problem:he has a  N\left( 1\leq N\leq {10}^{18}\right)  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) , 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) ,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

BestCoder Round #71 (div.2)



每次减一个尽可能小的木棒--


代码:

#include<cstdio>
#define LL long long
void solve()
{
    LL n;scanf("%lld",&n);
    if (n<3)
    {
        printf("1\n");
        return ;
    }
    LL shu[150];n-=3;
    shu[0]=1;shu[1]=2;
    for (int i=2;i;i++)
    {
        shu[i]=shu[i-1]+shu[i-2];
        if (n<shu[i])
        {
            printf("%d\n",i);
            return ;
        }
        n-=shu[i];
    }
}
int main()
{
    int t;scanf("%d",&t);
    while (t--)
        solve();
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值