hdoj 5620 KK's Steel (数学思维,那波婓切)

来源:互联网 发布:windows打印原理 编辑:程序博客网 时间:2024/06/03 01:41

KK's Steel

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


Problem Description
Our lovely KK has a difficult mathematical problem:he has aN(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
16
 

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)
 想不到……
从1开始贪心算,而且下一个不能大于前两个的和,不然就呈三角形,那就等于,正好f[i]=f[i-1]+f[i-2]
#include<cstdio>long long f[155];void F(){f[0]=0;f[1]=1;f[2]=2;for(int i=3;i<151;i++)f[i]=f[i-1]+f[i-2]; }  int main() { int t,ans; long long n; scanf("%d",&t);F();//printf("%lld %lld\n",f[50],f[140]);//50已经超int 140已经超2^18  while(t--) { scanf("%lld",&n); long long sum=0; for(int i=1;i<150;i++) { sum+=f[i]; if(sum>=n) { ans=i; break; }  } if(sum!=n) ans--; printf("%d\n",ans); } return 0; }


1 2 3 5 8
0 0