首页 > 其他 > 详细

HDU 5620 KK's Steel

时间:2016-02-14 15:27:52      阅读:208      评论:0      收藏:0      [点我收藏+]

想了一下发现是斐波那契数列.....水题

#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <queue>
#include <stack>
#include <map>
#include <vector>
using namespace std;

const int maxn=1000;
long long n;
long long a[maxn];

void init()
{
    a[1]=1; a[2]=2;
    for(int i=3;i<=90;i++) a[i]=a[i-1]+a[i-2];
}

int main()
{
    init();
    int T;
    scanf("%d",&T);
    while(T--)
    {scanf("%lld",&n);
        int ans;
        long long sum=0;
        for(int i=1;;i++)
        {
            sum=sum+a[i];
            if(sum<=n) ans=i;
            else break;
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

HDU 5620 KK's Steel

原文:http://www.cnblogs.com/zufezzt/p/5189050.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!