hdoj-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.

长为n的钢....拆分,要求每两段不一样,没三段不能构成三角,

肯定从1开始嘛,然后是2,然后不能构成三角形所以1+2=3,然后你会发现是斐波拉契数列

嗯...

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 1000 + 10;
const int maxt = 75 + 10;
typedef long long ll;
ll a[maxt];
int main()
{
    a[1] = 1;
    a[2] = 2;
    for (int i = 3 ; i < maxt; ++i)a[i] = a[i-1] + a[i-2];
    int n;
    cin >> n;
    while(n--){
        ll x;
        cin >> x;
        int i;
        ll sum = 0;
        for (i = 1; i < maxt; ++i){
            sum += a[i];
            if (sum > x)break;
        }
        if (x == 2 || x == 1){cout << 1 << endl;continue;}
        cout << i-1<< endl;
    }
    return 0;
}


你可能感兴趣的:(hdoj-5620-KK's Steel)