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; }