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(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 integerN(1≤N≤1018) ,indicating the length of the steel.
Each test case contains one line including a integer
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
3Hint1+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
- hdoj 5620 KK's Steel (数学思维,那波婓切)
- hdoj 5620 KK's Steel 【数学】
- hdoj-5620-KK's Steel
- 【斐波那契应用】HDOJ KK's Steel 5620
- HDOJ 5620-KK's Steel【斐波那契数列】
- HDU 5620 KK's Steel <贪心思维>
- hdoj KK's Steel 5620 (打表)
- hdoj--5620--KK's Steel(斐波那契数)
- HDU 5620 KK's Steel(思维题)
- HDU 5620 KK's Steel 斐波那契
- HDU 5620 KK's Steel
- HDU 5620 KK's Steel
- hdu KK's Steel【思维】【斐波那契数列应用】
- 杭电5620 KK's Steel
- HDU 5620 KK's Steel(水~)
- HDU 5620 KK's Steel(斐波那契数列的巧妙应用)
- KK's Steel bestcoder round 71 hdu 5620(裴波那契)
- HDU 5620 KK's Steel(找规律,斐波那契数列的应用)
- java中关于类、面向对象的简单介绍
- leetcode 135 candy 97 Interleaving String 316 Remove Duplicate Letters
- 【计算机网络-2】 【第一章】SDU与PDU 笔记
- C++常对象,常变量,常成员函数详解(含添加内容)
- HDU 5821-A - Ball-贪心
- hdoj 5620 KK's Steel (数学思维,那波婓切)
- JS中mouseover和mouseout多次触发问题如何解决
- CI的验证码代替类库(ci怎么加入验证码)
- 继续背单词,8个月过去了
- nginx代理后,获取request的ip
- TOJ 2761.Buy One Get One Free
- 常用的刷新技术(一)——SwipeRefresh
- 【CF 583C】
- 4、Java 包及访问控制权限