HDU 5620 KK's Steel (斐波那契序列)
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 (斐波那契序列)的更多相关文章
- pytho查找斐波那契序列中的值
''' 实现斐波那契序列,查找其中第N个数的值 ''' def FeiBSequence(list,N): length=len(list); i=0; while i<length: if N ...
- 爬楼梯问题-斐波那契序列的应用.md
N 阶楼梯,一次可以爬1.2.3...n步,求爬楼梯的种类数 /** * 斐波那契序列 */ public class ClimbingStairs { // Sol 1: 递归 // 递归 公式:F ...
- [LeetCode] Split Array into Fibonacci Sequence 分割数组成斐波那契序列
Given a string S of digits, such as S = "123456579", we can split it into a Fibonacci-like ...
- 利用python实现二分法和斐波那契序列
利用python实现二分法:我的实现思路如下 1.判断要查找的值是否大于最大值,如果大于则直接返回False 2.判断要查找的值是否小于最小值,如果小于则直接返回False 3.如果要查找的值在最大值 ...
- 最长斐波那契序列-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 ...
- 【严蔚敏】【数据结构题集(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阶斐 ...
- 【剑指offer】斐波那契序列与跳台阶
转载请注明出处:http://blog.csdn.net/ns_code/article/details/25337983 剑指offer上的第9题,简单题,在九度OJ上測试通过. 主要注意下面几点: ...
- hdu 5620 KK's Steel(推理)
Problem Description Our lovely KK has a difficult mathematical problem:he has a N(1≤N≤1018) meters s ...
- HDU 5620 KK's Steel
想了一下发现是斐波那契数列.....水题 #include <stdio.h> #include <algorithm> #include <string.h> # ...
随机推荐
- Android列表视图(List View)
Android列表视图(ListView) ListView是一个显示滚动项列表的示视图组(viewgroup),通过使用适配器(Adapter)把这些列表项自动插入到列表中.适配器比如从一个数组或是 ...
- bzoj2878
又是环套树dp,这次不是我擅长的类型 首先考虑树上的暴力,肯定是穷举起点然后以起点为根dp 我们用g[i]表示以点i为期望走的路径总长,答案就是1/n*Σ(g[i]/d[i]) (d[i]表示点度数) ...
- Ext.Net学习笔记01:在ASP.NET WebForm中使用Ext.Net
Ext.Net是一个对ExtJS进行封装了的.net控件库,可以在ASP.NET WebForm和MVC中使用.从今天开始记录我的学习笔记,这是第一篇,今天学习了如何在WebForm中使用Ext.Ne ...
- UVa 12230 (期望) Crossing Rivers
题意: 从A到B两地相距D,之间有n段河,每段河有一条小船,船的位置以及方向随机分布,速度大小不变.每段河之间是陆地,而且在陆地上行走的速度为1.求从A到B的时间期望. 分析: 我们只要分析每段河的期 ...
- textContent、innerText的用法,在文档中插入纯文本
有时候需要查询纯文本形式的元素内容,或者在文档中插入纯文本.标准的方法是用Node的textContent属性来实现: var para = document.getElementsByTagName ...
- EF 更新指定的字段
假如你有个表,有30个字段,你只想更新其中的1到2个字段的话,就可以用得上这篇文章 作用:类似于我们以前的sql代码 update xxx表 set name='ok',pwd='ok' where ...
- poj 1986 Distance Queries(LCA:倍增/离线)
计算树上的路径长度.input要去查poj 1984. 任意建一棵树,利用树形结构,将问题转化为u,v,lca(u,v)三个点到根的距离.输出d[u]+d[v]-2*d[lca(u,v)]. 倍增求解 ...
- jQuery的datatable怎么才能给某一列添加超链接?
aocolumeDef.这个里面去定义.return返回的字符串会代替原来cell里面的内容 e.g: datatable=$('#dt_basic').dataTable({ "bAuto ...
- 【JSP】三种弹出对话框的用法实例
对话框有三种 1:只是提醒,不能对脚本产生任何改变: 2:一般用于确认,返回 true 或者 false ,所以可以轻松用于 if...else...判断 3: 一个带输入的对话框,可以返回用户填入的 ...
- j2ee的13个标准
1:JDBC(Java Database Connectivity)JDBC API为访问不同数据库提供了统一的路径,向ODBC一样,JDBC开发者屏蔽了一些细节问题,另外,JDBC对数据库的访问也具 ...