题意:
小明有一根长度为a的木棒,现在小明想将木棒分为多段(每段木棒长度必须为整数),
使得分隔后的木棍中,取出的任意三段都不能构成三角形,小明想知道木棒最多被分成几段?
(就是题目嘻嘻~)
题解:知识点:有点斐波那契数列的意味在里面
三角形两边之和大于第三边,因此不构成三角形的条件就是存在两边之和不超过另一边。所以按照斐波那契数列的方法切割可以使得切割的段数最大,1,1,2,3,5这样可以使得任意三根木棒不能组成三角形,最后无法切割的部分组成一根长的木棒。
三角形两边之和大于第三边,也可以这样想,一个堆,将1放进去符合题意,放最小的数并且符合题意,第三个最小就是前两个数之和,也就是1 1 2,之后也是这样,所以就构成了,这个斐波那契数列。
需要注意的是用数据是
所以用unsigned long long
代码:
#include <queue> #include <string> #include<iostream> #include<stdio.h> #include<string.h> #include <algorithm> #include <math.h> typedef unsigned long long ull; using namespace std; typedef pair<ull,ull> pii; #define mem(a,x) memset(a,x,sizeof(a)) #define debug(x) cout << #x << ": " << x << endl; #define rep(i,n) for(int i=0;i<(n);++i) #define repi(i,a,b) for(int i=int(a);i<=(b);++i) #define repr(i,b,a) for(int i=int(b);i>=(a);--i) const int maxn=2e5+1010; #define inf 0x3f3f3f3f #define sf scanf #define pf printf const int mod=998244353; const int MOD=10007; inline int read() { int x=0; bool t=false; char ch=getchar(); while((ch<'0'||ch>'9')&&ch!='-')ch=getchar(); if(ch=='-')t=true,ch=getchar(); while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar(); return t?-x:x; } /*priority_queue<ll , vector<ll> , greater<ll> > mn;//上 小根堆 小到大 priority_queue<ll , vector<ll> , less<ll> > mx;//下 大根堆 大到小 map<ll,ll>mp;*/ ull n,m,t,l,r,p; ull sum,ans,res,cnt,flag,maxx,minn; bool isprime[maxn]; ull a[120],b[maxn],c[maxn]; ull dis[maxn],vis[maxn]; ull dp[1010][1010]; string str,s; #define read read() int main(){ cin>>t; a[1]=1; a[2]=1; for(int i=3;i<102;i++) a[i]=a[i-1]+a[i-2]; while(t--){ cin>>n; sum=0; for(int i=1;i<=100;i++) { if(n<a[i]) break; else { n-=a[i]; sum++; } } cout<<sum<<endl; } return 0; }