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. css link和@import区别用法

    这里link与@import介绍的是html引入css的语法单词.两者均是引入css到html的单词. 1.link语法结构<link rel="stylesheet" ty ...

  2. ACM刷题常用链接

    武汉科技大学  http://acm.wust.edu.cn/ 华中科技大学 http://acm.hust.edu.cn/vjudge/toIndex.action 杭州电子科技大学  http:/ ...

  3. POJ2135 最小费用最大流模板题

    练练最小费用最大流 此外此题也是一经典图论题 题意:找出两条从s到t的不同的路径,距离最短. 要注意:这里是无向边,要变成两条有向边 #include <cstdio> #include ...

  4. cd /d %~dp0

    cd /d %~dp0 注册服务的bat要用到,普通的执行没关系,但是用“管理员角色”执行,默认的起始目录会到  c:\windows\system 下,用上面一句可以回到当前执行bat的目录

  5. Ajax、Comet与Websocket

    从 http 协议说起 1996年IETF  HTTP工作组发布了HTTP协议的1.0版本 ,到现在普遍使用的版本1.1,HTTP协议经历了17 年的发展.这种分布式.无状态.基于TCP的请求/响应式 ...

  6. phonegap archive 报错 Cordova/CDVViewController.h' file not found

    在BuildSettings->Header Search Paths  增加如下路径,问题解决 $(OBJROOT)/UninstalledProducts/include "$(O ...

  7. [反汇编练习] 160个CrackMe之003

    [反汇编练习] 160个CrackMe之003. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...

  8. ti processor sdk linux am335x evm /bin/setup-targetfs-nfs.sh hacking

    #!/bin/sh # # ti processor sdk linux am335x evm /bin/setup-targetfs-nfs.sh hacking # 说明: # 本文主要对TI的s ...

  9. QPS、PV和需要部署机器数量计算公式(转)

    术语说明: QPS = req/sec = 请求数/秒 [QPS计算PV和机器的方式] QPS统计方式 [一般使用 http_load 进行统计] QPS = 总请求数 / ( 进程总数 *   请求 ...

  10. ffmpeg的内部Video Buffer管理和传送机制

    ffmpeg的内部Video Buffer管理和传送机制 本文主要介绍ffmpeg解码器内部管理Video Buffer的原理和过程,ffmpeg的Videobuffer为内部管理,其流程大致为:注册 ...