HDU 5620 KK's Steel(斐波那契数列的巧妙应用)
来源:互联网 发布:2016网络购物数据分析 编辑:程序博客网 时间:2024/06/05 04:15
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5620
题意:给一根长度为n的钢管,问最多能截成几段钢管,使得截成的钢管互不相等且均不能构成三角形
思路:斐波那契数列的巧妙应用,该开始没想到,以为是求公差为1的等差数列的和,这种思路是错误的,例如4.5.6就能组成三角形等等,假设a[0]=0,a[1] =1,则第47项斐波那契数列就会超int,刚开始数组开小了,结果数据错了,头一次遇到这种问题,代码中的2个数组可以压缩成一个数组,懒得改了
AC代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>#include <cctype>const int inf = 0x7f7f7f7f;//2139062143typedef long long ll;using namespace std;ll a[110],b[110];void cf(){ int i; a[1] = 1; b[1] = 1; a[2] = 2; b[2] = 3; for(i=3; i<100; i++) { a[i] = a[i-1] + a[i-2]; b[i] = b[i-1] + a[i]; }}int main(){ int t; cf(); scanf("%d",&t); while(t--) { ll sum; int i; scanf("%I64d",&sum); for(i=1; i<100; i++) { if(b[i] == sum) { break; } else if(b[i] > sum) { i--; break; } } printf("%d\n",i); } return 0;}
0 0
- HDU 5620 KK's Steel(斐波那契数列的巧妙应用)
- HDU 5620 KK's Steel(找规律,斐波那契数列的应用)
- HDOJ 5620-KK's Steel【斐波那契数列】
- hdu KK's Steel【思维】【斐波那契数列应用】
- HDU 5620 KK's Steel 斐波那契
- 【斐波那契应用】HDOJ KK's Steel 5620
- hd 5620 KK's Steel(斐波那契数列)
- KK's Steel<hdoj5620>菲波那切数列的应用
- KK's Steel bestcoder round 71 hdu 5620(裴波那契)
- BestCoder Round #71 (div.2)-KK's Steel(斐波那契数列)
- hdoj--5620--KK's Steel(斐波那契数)
- HDU 5620 KK's Steel(水~)
- HDU 5620 KK's Steel(简单的推理题)
- HDU 5620 KK's Steel
- HDU 5620 KK's Steel
- HDU 5620 KK's Steel(思维题)
- HDU 5620 KK's Steel <贪心思维>
- hdoj 5620 KK's Steel (数学思维,那波婓切)
- 13. Roman to Integer
- POJ 3682 King Arthur's Birthday Celebration 概率DP
- 191. Number of 1 Bits
- hdoj4288Coder【stl vector】
- bzoj1951【SDOI2010】古代猪文
- HDU 5620 KK's Steel(斐波那契数列的巧妙应用)
- 【运动传感器】Madgwick算法(上)
- 设计模式之建造者模式
- MySQLi基于面向过程的编程
- UVA 1593
- poj2481Cows【树状数组】
- CodeForces 294A Shaass and Oskols
- MySQLi基于面向对象的编程
- UVA 1594