hdoj--5620--KK's Steel(斐波那契数)
KK's Steel
Total Submission(s): 109 Accepted Submission(s): 48
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.
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.
1
6
3Hint1+2+3=6 but 1+2=3 They are all different and cannot make a triangle.
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
__int64 f[1000];
__int64 n;
int main()
{
int t;
scanf("%d",&t);
f[0]=1;
f[1]=1;
for(int i=2;i<=100;i++)
f[i]=f[i-1]+f[i-2];
while(t--)
{
cin>>n;
__int64 ans=1;
while(n)
{
n-=f[ans];
// printf("%d %d\n",n,f[ans]);
if(n<f[ans+1]) break;
ans++;
}
cout<<ans<<endl;
}
return 0;
}
hdoj--5620--KK's Steel(斐波那契数)的更多相关文章
- UVA 11582 Colossal Fibonacci Numbers! 大斐波那契数
大致题意:输入两个非负整数a,b和正整数n.计算f(a^b)%n.其中f[0]=f[1]=1, f[i+2]=f[i+1]+f[i]. 即计算大斐波那契数再取模. 一开始看到大斐波那契数,就想到了矩阵 ...
- 斐波那契数[XDU1049]
Problem 1049 - 斐波那契数 Time Limit: 1000MS Memory Limit: 65536KB Difficulty: Total Submit: 1673 Ac ...
- C++求斐波那契数
题目内容:斐波那契数定义为:f(0)=0,f(1)=1,f(n)=f(n-1)+f(n-2)(n>1且n为整数) 如果写出菲氏数列,则应该是: 0 1 1 2 3 5 8 13 21 34 …… ...
- Project Euler 104:Pandigital Fibonacci ends 两端为全数字的斐波那契数
Pandigital Fibonacci ends The Fibonacci sequence is defined by the recurrence relation: F[n] = F[n-1 ...
- DP:斐波纳契数
题目:输出第 n 个斐波纳契数(Fibonacci) 方法一.简单递归 这个就不说了,小n怡情,大n伤身啊……当n=40的时候,就明显感觉到卡了,不是一般的慢. //输出第n个 Fibonacci 数 ...
- HDU4549 M斐波那契数
M斐波那契数列 题目分析: M斐波那契数列F[n]是一种整数数列,它的定义例如以下: F[0] = a F[1] = b F[n] = F[n-1] * F[n-2] ( n > 1 ) 如今给 ...
- HDU 5914 Triangle(打表——斐波那契数的应用)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Problem Description Mr. Frog has n sticks, whos ...
- [Swift]LeetCode509. 斐波那契数 | Fibonacci Number
The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such th ...
- HDU 1021(斐波那契数与因子3 **)
题意是说在给定的一种满足每一项等于前两项之和的数列中,判断第 n 项的数字是否为 3 的倍数. 斐波那契数在到第四十多位的时候就会超出 int 存储范围,但是题目问的是是否为 3 的倍数,也就是模 3 ...
- POJ 3070(求斐波那契数 矩阵快速幂)
题意就是求第 n 个斐波那契数. 由于时间和内存限制,显然不能直接暴力解或者打表,想到用矩阵快速幂的做法. 代码如下: #include <cstdio> using namespace ...
随机推荐
- AFN上传多张图片
AFN上传多张图片代码: AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager]; sessionManager.r ...
- Laravel5.1学习笔记7 视图
视图 (View) 基本用法 传递数据到视图 在多个视图中分享数据 视图组件 #基本用法 视图里面包含了你应用程序所提供的 HTML 代码,并且提供一个简单的方式来分离控制器和网页呈现上的逻辑.视 ...
- 【MFC】在MFC中PreTranslateMessage()的使用方法
BOOL CSearchuserDlg::PreTranslateMessage(MSG* pMsg) { if (pMsg->message==WM_KEYDOWN) // 判断是否有按键按下 ...
- 英语之ASIC
ASIC(Application Specific Integrated Circuit) = 专用集成电路 assign = [计][数] 赋值 assign a value 分配一个值:赋值
- selenium菜单操作
连接到前端这个菜单下面的HTML/CSS子菜单 driver.get("https://www.imooc.com"); WebElement login = driver.fin ...
- html中的小知识
引用外部样式 样式表,如果是引用外部样式,不需要再写style标签了,因为 <link rel="stylesheet" type="text/css" ...
- react基础篇一
jsx简介 const element = <h1>Hello, world!</h1>; 这种看起来可能有些奇怪的标签语法既不是字符串也不是 HTML. 它被称为 JSX, ...
- Type class-Typeclass-泛型基础上的二次抽象---随意多态
对泛型的类型添加约束,从而使泛型类型的变量具有某种通用操作. 再使用这些操作,参与到其它操作中. In computer science, a type class is a type system ...
- iOS https 证书链获取
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)chall ...
- 浅谈Web缓存-缓存的实现过程详解
在前端开发中,性能一直都是被大家所重视的一点,然而判断一个网站的性能最直观的就是看网页打开的速度.其中提高网页反应速度的一个方式就是使用缓存.一个优秀的缓存策略可以缩短网页请求资源的距离,减少延迟,并 ...