KK's SteelTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 497 Accepted Submission(s): 236
Problem Description
Our lovely KK has a difficult mathematical problem:he has a
N(1≤N≤1018)
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(1≤T≤10)
, which indicates the number of test cases.
Each test case contains one line including a integer N(1≤N≤1018) ,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
Sample Output
Source
Recommend
|
题意:
解题思路:题意简单。。。
开始以为是个规律,直接除2了。。。。。。。wa了发现不对。。斐波那契数列,因为为了保持后边的数尽可能小,所以最大就等于前面的2个数相加。。这样一直下去就是斐波那契数列了。。
AC代码:
#include <stdio.h> using namespace std; typedef long long LL; LL f[1000]; int main() { f[0]=1;f[1]=2; for(int i=2;i<1000;i++){ f[i]=f[i-1]+f[i-2]; } int t; scanf("%d",&t); while(t--){ LL n; scanf("%lld",&n); int i; LL ans=0; for(i=0;ans<=n;i++){ ans+=f[i]; } if(ans>n)i--; printf("%d\n",i); } return 0; }