KK's Steel<hdoj5620>菲波那切数列的应用
2016-07-27 21:45
232 查看
Description
Our lovely KK has a difficult mathematical problem:he has a N\left( 1\leq N\leq {10}^{18}\right) 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\left( 1\leq T\leq 10\right),
which indicates the number of test cases.
Each test case contains one line including a integer N\left( 1\leq N\leq {10}^{18}\right),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
1
6
Sample Output
3
Hint
1+2+3=6 but 1+2=3 They are all different and cannot make a triangle.
把一个数分成不等的数相加 并且这些数任意三个不能构成三角形
直接求这个数可以分出多少个菲波那切数
#include<bits/stdc++.h>
__int64 zu[200001];
int main()
{
for(__int64 i=2;i<200001;i++)
{
zu[1]=1;
zu[2]=2;
zu[i+1]=zu[i]+zu[i-1];
}
__int64 t,n;
scanf("%I64d",&t);
while(t--)
{
__int64 cut=0;
scanf("%I64d",&n);
if(n<6)
{
printf("0\n");
continue;
}
for(__int64 i=1;i<200001;i++)
{
n-=zu[i];
if(n<0)
{
break;
}
cut++;
}
printf("%I64d\n",cut);
}
return 0;
}
Our lovely KK has a difficult mathematical problem:he has a N\left( 1\leq N\leq {10}^{18}\right) 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\left( 1\leq T\leq 10\right),
which indicates the number of test cases.
Each test case contains one line including a integer N\left( 1\leq N\leq {10}^{18}\right),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
1
6
Sample Output
3
Hint
1+2+3=6 but 1+2=3 They are all different and cannot make a triangle.
把一个数分成不等的数相加 并且这些数任意三个不能构成三角形
直接求这个数可以分出多少个菲波那切数
#include<bits/stdc++.h>
__int64 zu[200001];
int main()
{
for(__int64 i=2;i<200001;i++)
{
zu[1]=1;
zu[2]=2;
zu[i+1]=zu[i]+zu[i-1];
}
__int64 t,n;
scanf("%I64d",&t);
while(t--)
{
__int64 cut=0;
scanf("%I64d",&n);
if(n<6)
{
printf("0\n");
continue;
}
for(__int64 i=1;i<200001;i++)
{
n-=zu[i];
if(n<0)
{
break;
}
cut++;
}
printf("%I64d\n",cut);
}
return 0;
}
相关文章推荐
- 知识:树同构判断
- Windows的免費hMailServer搭配SpamAssassin過濾垃圾郵件:安裝與設定
- [工具] Firemonkey Style 调色工具(可另存 Style 文件)
- 语音合成与语音识别小例子
- activity生命周期
- HDU 1083 COURSES 【二分图最大匹配】
- Date和Calendar类的一些使用
- 中兴盒子第三方软件通用教程安装教程
- 第一章+第二章阅读笔记
- Linux中的信号(2)
- 自动对焦的原理
- Java Map集合的详解
- Java中的数组
- 原生js,JQuery查找元素,修改类名
- UVALive 3635 Pie 【二分】
- 2017百度实习生招聘算法题
- mysql的四种类型时间
- coderforces 348A Mafia(二分)
- 线索二叉树
- ubuntu14.04+cuda-7.5(deb)+cuDNN+openCV+caffe 安装(安装笔记一)