BestCoder Round #71 (div.2) (hdu 5620 菲波那切数列变形)

时间:2022-12-20 19:32:13

KK's Steel

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

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 integer N(1≤N≤1018),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.

 
要求:给一个长整形数n让你把n分成若干份,1、任意两份长度不能相等 2、任意三分不能组成三角形
 
分析:因为斐波那契数列中的数满足此要求,所以从这个方面入手,只要分成的数满足a+b<=c即可,所以我们在数列1  2  3  5  8  13  21 ......的数中选取,如果前i项的和等于n输出i如果前i项的和大于n输出i-1
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#define MAX 100100
#define INF 0x3f3f3f
#define LL long long
using namespace std;
LL fb[10010];
LL f[1001];
void biao()
{
LL i,j;
fb[1]=1;
fb[2]=2;
for(i=3;i<120;i++)
fb[i]=fb[i-1]+fb[i-2];
f[1]=fb[1];
for(i=2;i<120;i++)
f[i]=f[i-1]+fb[i];
}
int main()
{
int t,i,j;
LL n;
biao();
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
for(i=1;i<120;i++)
{
if(n==f[i])
{
printf("%d\n",i);
break;
}
if(n<f[i])
{
printf("%d\n",i-1);
break;
}
}
}
return 0;
}

  

BestCoder Round #71 (div.2) (hdu 5620 菲波那切数列变形)的更多相关文章

  1. 菲波那切数列&lpar;Fibonacci Number&rpar;

    什么是菲波那切数列?自己google一下,面试题里面经常遇到,考试递归算法用的. 在菲波那切数列中用递归不太好.第三种算法最好. 第一 递归算法最差了,不想说.测试一下,当N=6000时,半天出不来数 ...

  2. BestCoder Round &num;71 &lpar;div&period;2&rpar; (hdu 5621)

    KK's Point Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. BestCoder Round &num;71 &lpar;div&period;2&rpar;

    数学 1001 KK's Steel 类似斐波那契求和 #include <cstdio> #include <cstring> #include <algorithm& ...

  4. BestCoder Round &num;52 &lpar;div&period;2&rpar; HDU 5418 Victor and World &lpar;DP&plus;状态压缩&rpar;

    [题目链接]:pid=5418">click here~~ [题目大意]: 问题描写叙述 经过多年的努力,Victor最终考到了飞行驾照. 为了庆祝这件事,他决定给自己买一架飞机然后环 ...

  5. php实现菲波那切数列和杨辉三角

    1.递归  显示斐波那契数列 <?PHP         function recursion($num){               //判断是否小于0               if($ ...

  6. hdu 5636 搜索 BestCoder Round &num;74 &lpar;div&period;2&rpar;

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  7. BestCoder Round &num;69 &lpar;div&period;2&rpar; Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  8. BestCoder Round &num;68 &lpar;div&period;2&rpar; tree(hdu 5606)

    tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  9. hdu5634 BestCoder Round &num;73 &lpar;div&period;1&rpar;

    Rikka with Phi  Accepts: 5  Submissions: 66  Time Limit: 16000/8000 MS (Java/Others)  Memory Limit: ...

随机推荐

  1. &lbrack;LeetCode&rsqb; Shuffle an Array 数组洗牌

    Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...

  2. BAYSY2 的LVDS引脚 笔记

    差分引脚标号说明: 'L' 代表该引脚属于差分引脚 'xx' 两位整型数,在每一 bank 的独特标记 'y' 表示正向 还是 反向,同时要注意输入输出方向 ‘#’ 0~3,代表 bank0~bank ...

  3. node递归属性目录结构

    要求,读取结束后才能输出所有文件 var fs = require('fs');var path = require('path'); var list = [];var count = 0;func ...

  4. Win7下JDK环境变量的设置

    JDK并不像Microsoft阵营vs那样智能,安装好后所有的东西都给你配置好了,我们还没需要手动配置很多东西 首先说为什么要配置JDK的环境变量在任何路径下识别java命令和java类 配置分为2个 ...

  5. Linux TC &lpar;traffic control&rpar;

    在着手学习TC采用如下单位来描述带宽: mbps = 1024 kbps = 1024 * 1024 bps => byte/s mbit = 1024 kbit => kilo bit/ ...

  6. Qt5&period;3企业版和开源版功能区别

    一: Charts Charts是QT提供的图表模块.他提供了非常简便的APIs来绘制令人惊叹的Line, Spline,Area,Scatter,Pie,Donut,Bar,Polar和Box-an ...

  7. android okhttp的使用

    OkHttpClient client = new OkHttpClient(); String url = ""; Request request = new Request.B ...

  8. Python中的对象行为与特殊方法&lpar;一&rpar;对象的创建与销毁

    Python中类调用__new__()类方法来创建实例,调用__init__()方法来初始化对象,对象的销毁则调用__del__()方法. __new__()方法第一个参数为类cls,通常返回cls的 ...

  9. 面向对象的轮播js

    1.自执行函数的前后要加分号 案例: ;(function(){})(); 2.面向对象的最大优势节省了许多内存 正式开写面向对象的轮播: <!DOCTYPE html> <html ...

  10. VFS&colon; Cannot open root device &quot&semi;nfs&quot&semi; or unknown-block&lpar;0&comma;255&rpar;错误的解决

    1. 解决办法:在内核配置时候文件系统中选中Root file system on NFS