zoukankan      html  css  js  c++  java
  • hdu 5620

    KK's Steel

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


    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
     
    题意: n米长的钢管切成若干段 要求每段 长度不同 且任意三段不能组成三角形 问最多能分成多少段
    题解: 易发现 满足斐波那契数列
     
      
    #include<iostream>
    #include<cstdio>
    #define LL __int64
    using namespace std;
    int main()
    {
        int t;
        LL n;
        scanf("%d",&t);
        for(int i=1;i<=t;i++)
        {
            scanf("%I64d",&n);
            LL exm=1;
            LL ans=0;
            LL flag=1;
            while(n>=exm)
            {
                LL gg;
                gg=exm;
              ans++;
              n-=exm;
              exm+=flag;
              flag=gg;
              //cout<<flag<<" "<<exm<<endl;
            }
            printf("%I64d
    ",ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    20200318
    20200317
    Thinkphp 操作多个数据库
    base格式图片转文件存储
    Thinkphp POST 和 GET 传值
    Thinkphp调用微信扫一扫实例,学会再也不怕客户在微信提的奇葩要求了
    centos 安装ngnix mysql php
    PHP 区分微信、支付宝、QQ扫码
    PHP秒数计算时分秒
    Thinkphp 获取访问者的ip
  • 原文地址:https://www.cnblogs.com/hsd-/p/5184964.html
Copyright © 2011-2022 走看看