• hdu 5620 KK's Steel(推理)


     

    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的钢管,问最多切成几个钢管,使得这些钢管不能围成三角形,并且不能有相同长度 !
    思路:
    要想使得钢管尽量多,那肯定从1开始吧,有了1,且不能重复,那肯定找2吧,而且三个钢管不能围成,三角形,那直接找a1 + a2 = a3的情况不就恰好不能围成三角形吗。所以很明显,这是一个a1 = 1,a2 = 2的斐波那契数列,找到第一个i  是的前i项和大于N,即可!特殊判断N = 1,N=2即可!他们都是1!
     
     1 #pragma comment(linker, "/STACK:1024000000,1024000000")
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<math.h>
     7 #include<algorithm>
     8 #include<queue>
     9 #include<set>
    10 #include<bitset>
    11 #include<map>
    12 #include<vector>
    13 #include<stdlib.h>
    14 using namespace std;
    15 #define ll long long
    16 #define eps 1e-10
    17 #define MOD 1000000007
    18 #define N 1000000
    19 #define inf 1e12
    20 ll n;
    21 ll f[N];
    22 void init(){
    23     f[1]=1;
    24     f[2]=2;
    25     for(ll i=3;i<N;i++){
    26         f[i]=f[i-2]+f[i-1];
    27     }
    28 }
    29 int main()
    30 {
    31     init();
    32     int t;
    33     scanf("%d",&t);
    34     while(t--){
    35         scanf("%I64d",&n);
    36         ll sum=0;
    37         ll i;
    38         for(i=1;i<N;i++){
    39             sum+=f[i];
    40             if(sum>n){
    41                 break;
    42             }
    43         }
    44         if(n==1 || n==2){
    45             printf("1
    ");
    46             continue;
    47         }
    48         printf("%I64d
    ",i-1);
    49     }
    50     return 0;
    51 }
    View Code
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    SQL Server-数据库架构和对象、定义数据完整性(二)
    SQL Server-语句类别、数据库范式、系统数据库组成(一)
    ASP.NET WebAPi之断点续传下载(下)
    ConcurrentDictionary线程不安全么,你难道没疑惑,你难道弄懂了么?
    ASP.NET WebAPi之断点续传下载(中)
    ASP.NET WebAPi之断点续传下载(上)
    ASP.NET WebAPi(selfhost)之文件同步或异步上传
    JSTL fn:contains()函数
    用jstl标签判断一个字符串是否包含了另一个字符串
    fn:replace()函数
  • 原文地址:https://www.cnblogs.com/UniqueColor/p/5184845.html
Copyright © 2020-2023  润新知