hdu 5620
2016-02-08 12:48
253 查看
KK's Steel
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 197 Accepted Submission(s): 90
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, output one line, an integer represent the maxiumum number of steels he can cut it into.
[align=left]Sample Input[/align]
1
6
[align=left]Sample Output[/align]
3
Hint
1+2+3=6 but 1+2=3 They are all different and cannot make a triangle.
[align=left]Source[/align]
BestCoder Round #71 (div.2)
题意: n米长的钢管切成若干段 要求每段 长度不同 且任意三段不能组成三角形 问最多能分成多少段
题解: 易发现 满足斐波那契数列
#include<iostream> #include<cstdio> #define LL __int64 using namespace std; int main() { int t; LL n; scanf("%d",&t); for(int i=1;i<=t;i++) { scanf("%I64d",&n); LL exm=1; LL ans=0; LL flag=1; while(n>=exm) { LL gg; gg=exm; ans++; n-=exm; exm+=flag; flag=gg; //cout<<flag<<" "<<exm<<endl; } printf("%I64d\n",ans); } return 0; }
相关文章推荐
- YTU 2633: P3 数钱是件愉快的事
- YTU 2632: B2 友元光顾
- YTU 2631: B1 能存各种类型数据的Store类
- Codeforces 625 D Finals in arithmetic
- YTU 2630: E2 驾驭const
- YTU 2629: E1 一种颜色,三个分量
- cocos2dx3.2 异步加载和动态加载
- 哈理工 1170 语法检查-括号匹配【stack应用】【水题~】
- YTU 2626: B 统计程序设计基础课程学生的平均成绩
- JAVA 内部类、外部类、继承、抽象类、接口实战
- YTU 2625: B 构造函数和析构函数
- 聊聊软件测试04
- 二进制中1的个数
- YTU 2623: B 抽象类-形状
- Codeforces Round #342 (Div 2) 解题报告
- Codeforces Round #342 (Div 2) 解题报告
- cocos2dx3.0 超级马里奥开发笔记(一)——loadingbar、TableView和pageview的使用
- Two Sigma OA
- IoSkipCurrentIrpStackLocation macro
- 关于主线程中自动建立的Looper的思考:主线程中Looper中的轮询死循环为何没有阻塞主线程