KK's Steel

题目链接:

http://acm.hust.edu.cn/vjudge/contest/121332#problem/J

Description

Our lovely KK has a difficult mathematical problem:he has a 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 , which indicates the number of test cases.

Each test case contains one line including a integer ,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最多能由分成多少个不同的斐波那契数之和即可.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#define LL long long
#define eps 1e-8
#define maxn 3300
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std; LL n; int main(int argc, char const *argv[])
{
//IN; int t; cin >> t;
while(t--)
{
scanf("%I64d", &n);
if(n==1 || n==2) {printf("1\n");continue;}
int cnt = 2;
LL first = 1;
LL second = 2;
n -= 3;
while(1) {
if(n <=0) break;
LL tmp = second;
second = first + second;
first = tmp;
n -= second;
cnt++;
} if(n!=0) cnt--;
printf("%d\n", cnt);
} return 0;
}

HDU 5620 KK's Steel (斐波那契序列)的更多相关文章

  1. pytho查找斐波那契序列中的值

    ''' 实现斐波那契序列,查找其中第N个数的值 ''' def FeiBSequence(list,N): length=len(list); i=0; while i<length: if N ...

  2. 爬楼梯问题-斐波那契序列的应用.md

    N 阶楼梯,一次可以爬1.2.3...n步,求爬楼梯的种类数 /** * 斐波那契序列 */ public class ClimbingStairs { // Sol 1: 递归 // 递归 公式:F ...

  3. [LeetCode] Split Array into Fibonacci Sequence 分割数组成斐波那契序列

    Given a string S of digits, such as S = "123456579", we can split it into a Fibonacci-like ...

  4. 利用python实现二分法和斐波那契序列

    利用python实现二分法:我的实现思路如下 1.判断要查找的值是否大于最大值,如果大于则直接返回False 2.判断要查找的值是否小于最小值,如果小于则直接返回False 3.如果要查找的值在最大值 ...

  5. 最长斐波那契序列-LeetCode-873

    英文版A sequence X_1, X_2, ..., X_n is fibonacci-like if: - n >= 3- X_i + X_{i+1} = X_{i+2} for all ...

  6. 【严蔚敏】【数据结构题集(C语言版)】1.17 求k阶斐波那契序列的第m项值的函数算法

    已知k阶斐波那契序列的定义为 f(0)=0,f(1)=0,...f(k-2)=0,f(k-1)=1; f(n)=f(n-1)+f(n-2)+...+f(n-k),n=k,k+1,... 试编写求k阶斐 ...

  7. 【剑指offer】斐波那契序列与跳台阶

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/25337983 剑指offer上的第9题,简单题,在九度OJ上測试通过. 主要注意下面几点: ...

  8. hdu 5620 KK's Steel(推理)

    Problem Description Our lovely KK has a difficult mathematical problem:he has a N(1≤N≤1018) meters s ...

  9. HDU 5620 KK's Steel

    想了一下发现是斐波那契数列.....水题 #include <stdio.h> #include <algorithm> #include <string.h> # ...

随机推荐

  1. Hibernate框架简述

    Hibernate的核心组件在基 于MVC设计模式的JAVA WEB应用中,Hibernate可以作为模型层/数据访问层.它通过配置文件(hibernate.properties或 hibernate ...

  2. openVPN使用

    http://www.williamlong.info/archives/3814.html http://openvpn.ustc.edu.cn/ http://www.williamlong.in ...

  3. hdu 4973 A simple simulation problem. (线段树)

    题目链接 题意: 给定n长的序列 m个操作 序列默认为 1, 2, 3···n 操作1:D [l,r] 把[l,r]区间增长 :( 1,2,3,4 进行 D [1,3]变成 1,1,2,2,3,3,4 ...

  4. hdu 4864 Task (贪心 技巧)

    题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi& ...

  5. android线程池

    线程池的基本思想还是一种对象池的思想,开辟一块内存空间,里面存放了众多(未死亡)的线程,池中线程执行调度由池管理器来处理.当有线程任务时,从池中取一个,执行完成后线程对象归池,这样可以避免反复创建线程 ...

  6. bzoj3140

    首先考虑二维的情况 min(x,y)也就意味着确定最小后,另外一维肯定打满 然后最小那个如果是k的话就相当于用k*1次——这不就是行列覆盖吗,二分图秒之 三维呢?考虑到a*b*c<=5000也就 ...

  7. js 写成类的形式 js 静态变量 js方法 属性 json类

    function ClassStudentList() { //[{"Cid":"0d","Students":[{"Sid&qu ...

  8. zoj 2588 Burning Bridges

    题目描述:Ferry王国是一个漂亮的岛国,一共有N个岛国.M座桥,通过这些桥可以从每个小岛都能到达任何一个小岛.很不幸的是,最近Ferry王国被Jordan征服了.Jordan决定烧毁所有的桥.这是个 ...

  9. 未能加载文件或程序集“Oracle.DataAccess, Version=2.112.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"

    转载自原文 未能加载文件或程序集"Oracle.DataAccess, Version=2.112.1.0,..." 若本机的Oracle版本是32位系统,则在调用Oracle数据 ...

  10. [Papers]NSE, $u_3$, Lebesgue space [NNP, QM, 2002; Zhou, JMPA, 2005]

    $$\bex u_3\in L^p(0,T;L^q(\bbR^3)),\quad \frac{2}{p}+\frac{3}{q}=\frac{1}{2},\quad 6< q\leq \inft ...