TOJ 3845.Cut Stick(斐波那契)
来源:互联网 发布:测试手机信号强度软件 编辑:程序博客网 时间:2024/05/16 03:14
题目链接:http://acm.tju.edu.cn/toj/showp3845.html
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 546 Accepted Runs: 259
Ann meets another problem.
Since she has a n-meter-long stick, she wants to cut it into small ones. Of course she would not let the small sticks shorter than 1 meter. At the same time she is so mean that she can't stand that any three of the small sticks could spell a triangle. That is to say, any 3 of the small sticks can not form a triangle if there are 3 or more small sticks.
You can simple assume that the small sticks only have integer length.
Input
A line contains a positive integer n, which is the length of the long sticks. It does not exceed 10^5.
Output
Print a number -- the maximum number of small sticks Ann could get.
Sample Input
1234
Sample Output
1223
Source: TJU 2012 Team Selection
剪棍子,在满足任意三根木棍不能构成三角形的前提下问最多可以剪成几根。众所周知,构成三角形的条件是任意两边的长度要大于第三边的长度,因此为了尽可能多的剪,所以从1开始,每次剪棍子都要满足不大于(也就是等于)前边两次剪得长度和:
#include <stdio.h>using namespace std;int main(){int l;while(~scanf("%d",&l)){int a=0,b=1,m;for(m=1;;m++){l-=b;if(a+b>l)break;int tmp=a;a=b;b+=tmp;}printf("%d\n",m);}}
按此思路写完才发现,这不就是斐波那契数列么,于是悲伤地用斐波那契重写了一遍。。。
#include <stdio.h>int febo[100001]={1,1};int main(){for(int i=2;i<100001;i++)febo[i]=febo[i-1]+febo[i-2];int l,m;while(~scanf("%d",&l)){m=0;while(l>=febo[m])l-=febo[m++];printf("%d\n",m);}}
- TOJ 3845.Cut Stick(斐波那契)
- TOJ 1345 大数斐波那契数列
- TJU-3845 Cut Stick(贪心)
- Stick
- Stick
- Stick
- stick
- stick
- stick
- stick
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 【POJ2463】Bungee Jumping
- 关于乱码的一些总结--项目过程的点点滴滴
- 很漂亮的bootstrap ace静态页面后台管理系统模板
- 跟我学Redis(15)—Redis主从复制
- 8、对象的容纳
- TOJ 3845.Cut Stick(斐波那契)
- 静态库的编写与使用
- POJ 1321 棋盘问题
- centos下使用crontab执行php定时任务
- PAT乙级:1013. 数素数 (C)
- D3.js SVG绘图实践:趋势缩略图
- 【知识积累】Spring Web MVC学习(一)
- PAT-A 1002.A+B for Polynomials
- Pair: normal and paranormal 栈的应用