hd 5620 KK's Steel(斐波那契数列)

    xiaoxiao2025-12-31  11

    KK's Steel

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1009    Accepted Submission(s): 487 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. 题意:给你一根长为n的木棒,怎你最多能把它分成多少段,并且要求任意两段长度不相等,任意三段不能组成三角形 思路:通过观察,只能分成 1 2 3 5 8 13 21 .......... 即斐波那契数列 #include<cstdio> #define LL long long int int main() { int t; LL n; LL f[100]; f[1] = 1; f[2] = 2; for(int i = 3 ; i <= 85 ; i++) { f[i] = f[i-1] + f[i-2]; } scanf("%d",&t); while(t--) { LL sum = 0; int falg = 0;- scanf("%I64d",&n); for(int i = 1 ; i <= 85 ; i++){ sum += f[i]; if(sum >= n) { falg = i; break; } } if(sum != n) falg--; printf("%d\n",falg); } return 0; }  
    转载请注明原文地址: https://ju.6miu.com/read-1305500.html
    最新回复(0)