码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5620 KK's Steel

时间:2016-02-14 15:28:15      阅读:127      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!