Codeforce Round #382 (div 1) A
2017-07-18 09:41
369 查看
算是一个找规律的问题
是一个斐波那契数列
1 对应0
2对应1
3对应 2
5对应3
昨天晚上补得的时候开的数组过大,溢出了,所以用upper_bound是不行的, 前提的一个有序的数列
没想到100就到10的19次了 昨天晚上开了个10w的。。。
代码如下
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
long long a[105];
a[0]=1; a[1]=2;
for(int i=2;i<105;i++)
a[i]=a[i-1]+a[i-2];
long long n;
scanf("%lld",&n);
printf("%d",upper_bound(a,a+100,n)-a-1);
}
是一个斐波那契数列
1 对应0
2对应1
3对应 2
5对应3
昨天晚上补得的时候开的数组过大,溢出了,所以用upper_bound是不行的, 前提的一个有序的数列
没想到100就到10的19次了 昨天晚上开了个10w的。。。
代码如下
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
long long a[105];
a[0]=1; a[1]=2;
for(int i=2;i<105;i++)
a[i]=a[i-1]+a[i-2];
long long n;
scanf("%lld",&n);
printf("%d",upper_bound(a,a+100,n)-a-1);
}
相关文章推荐
- Codeforce Round #220 Div2
- Codeforces Round #382 (Div. 2) C. Tennis Championship 递推、斐波拉契数列
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B(模拟) && codeforce 724B Batch Sort
- CodeForce Round 219 Div2 E Watching Fireworks is Fun 单调队列DP
- Codeforce Round #224 Div2
- CodeForce Round 258 div2
- CodeForce Round 257 div2
- CodeForce Round 215 DIV2 C 使用了线段树 但是多此一举...
- Codeforce Round #226 Div2
- Codeforce Round #228 Div2
- Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]
- Codeforces Round #382 (Div. 1) 736B Taxes
- Codeforces Round #382 (Div. 1) B. Taxes
- codeforce Round #232 Div2 map + 质因子 +组合
- Codeforces Round #382 (Div. 2) 735B - Urbanization
- Codeforces Round #382 (Div. 2)
- Codeforces Round #382 (Div. 2)-735C. Tennis Championship(递推)
- Codeforces Round #382 (Div. 1) B. Taxes
- Codeforce Round 363(Div2)A(Java)
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心