【斐波那契应用】HDOJ KK's Steel 5620
来源:互联网 发布:昆明市网络预约出租车 编辑:程序博客网 时间:2024/06/05 16:57
KK's Steel
Time 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 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)
Recommend
hujie | We have carefully selected several similar problems for you: 5634 5633 5632 5631 5630
题意:
解题思路:题意简单。。。
开始以为是个规律,直接除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;}
0 0
- 【斐波那契应用】HDOJ KK's Steel 5620
- HDOJ 5620-KK's Steel【斐波那契数列】
- hdoj--5620--KK's Steel(斐波那契数)
- HDU 5620 KK's Steel 斐波那契
- HDU 5620 KK's Steel(斐波那契数列的巧妙应用)
- HDU 5620 KK's Steel(找规律,斐波那契数列的应用)
- hdoj-5620-KK's Steel
- hdu KK's Steel【思维】【斐波那契数列应用】
- hdoj 5620 KK's Steel (数学思维,那波婓切)
- hd 5620 KK's Steel(斐波那契数列)
- hdoj 5620 KK's Steel 【数学】
- hdoj KK's Steel 5620 (打表)
- KK's Steel bestcoder round 71 hdu 5620(裴波那契)
- BestCoder Round #71 (div.2)-KK's Steel(斐波那契数列)
- KK's Steel<hdoj5620>菲波那切数列的应用
- HDU 5620 KK's Steel
- HDU 5620 KK's Steel
- 杭电5620 KK's Steel
- 收获与努力同行——2015年总结
- 岁月划过生命线——考研工作篇
- JSP_005_HttpSession之概述
- linux 如何查找命令的路径
- Stream 流环境配置流程过程介绍
- 【斐波那契应用】HDOJ KK's Steel 5620
- 获取select的选择值
- UIViewAnimationOption的枚举
- 第七届蓝桥杯全国软件和信息技术专业人才大赛竞赛注意事项
- Eclipse输入Java和XML代码自动提示功能最简单的方法
- SQL GROUP BY 语句
- assign copy retain weak strong 区别【读Effective Objective-C 2.0 编写高质量iOS与OS X代码的52个有效方法】
- 【杭电oj】3785 - 寻找大富翁(水)
- 【慕课笔记】第六章 JAVA中的集合框架(下) 第4节 学生选课——判断Map中是否包含指定的key和value