HDOJ_2041_大二寫_超級電梯
阿新 • • 發佈:2018-11-10
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; }