HDU 5620 KK's Steel

KK's Steel

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


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
BestCoder Round #71 (div.2)
 
大体题意:
给你一个长度为N的钢管,问最多切成几个钢管,使得这些钢管不能围成三角形,并且不能有相同长度 !
分析:
开始想感觉好麻烦,其实仔细想想吧:
要想使得钢管尽量多,那肯定从1开始吧,有了1,且不能重复,那肯定找2吧,而且三个钢管不能围成,三角形,那直接找a1 + a2 = a3的情况不就恰好不能围成三角形吗。所以很明显,这是一个a1 = 1,a2 = 2的斐波那契数列,找到第一个i  是的前i项和大于N,即可!特殊判断N = 1,N=2即可!他们都是1!感觉这里题目阐述有点不理解!!


#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<cctype>
#include<cstdlib>
#define mem(x) memset(x,0,sizeof(x));
#define mem1(x) memset(x,-1,sizeof(x));
using namespace std;
const int maxn = 1000 + 10;
const int maxt = 75 + 10;
const double eps = 1e-8;
const int INF = 1e8;
const double pi = acos(-1.0);
typedef long long ll;
typedef unsigned long long llu;
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;
}


你可能感兴趣的:(C语言)