HDOJ_2041_大二写_超级电梯

AC代码:

#include <iostream>
#include <cstdio>
using namespace std;
int main(void)
{
    freopen("in.txt","r",stdin);
    int N;
    scanf("%d",&N);
    while(N--)
    {
        int m;
        long long sum,sum1,sum2;
        scanf("%d",&m);
        sum1=1;
        sum2=2;
        if(m==1)
            sum=0;
        else if(m==2)
            sum=sum1;
        else if(m==3)
            sum=sum2;
        else
            for(int i=4;i<=m;i++)
            {
                sum=sum1+sum2;
                sum1=sum2;
                sum2=sum;
            }
        printf("%d\n",sum);
        
    }
    
    fclose(stdin);
    return 0;
} 

 

posted @ 2018-11-10 09:05  pha创噬  阅读(86)  评论(0编辑  收藏  举报