NC200121. Logs Stacking
描述
输入描述
There are multiple test cases. The first line of the input contains an integer T (1 ≤ T ≤ ), indicating the number of test cases. For each test case:
Each line contains one integer n (1 ≤ n ≤ 2×), indicating the total number of logs.
输出描述
For each test case in the input, you should output the corresponding number of possible figures.
Because the number may be very large, just output the number mod 10000.
示例1
输入:
5 1 3 5 7 2000000000
输出:
1 2 5 13 3125
说明:
In the third sample, you can accumulate 5 logs within such following ways:C(clang 3.9) 解法, 执行用时: 24ms, 内存消耗: 984K, 提交时间: 2019-12-07 22:10:26
#include<stdio.h> int main(){ int ans[2000005]; ans[1]=1; ans[2]=1; for(int i=3;i<100000;i++){ ans[i]=(ans[i-1]+ans[i-2])%10000; } int t; scanf("%d",&t); while(t--){ long long n; scanf("%lld",&n); n%=15000; printf("%d\n",ans[n]); } }
C++11(clang++ 3.9) 解法, 执行用时: 28ms, 内存消耗: 1264K, 提交时间: 2019-12-11 14:16:37
#include<cstdio> int num[15005]; int main(){ int i,n,t; num[0]=0;num[1]=num[2]=1; for(i=3;i<=15000;i++){ num[i]=(num[i-1]+num[i-2]+10000)%10000; } while(scanf("%d",&t)!=EOF){ while(t--){ scanf("%d",&n); printf("%d\n",num[n%15000]); } } return 0; }
C++14(g++5.4) 解法, 执行用时: 20ms, 内存消耗: 864K, 提交时间: 2019-12-07 18:09:39
#include<bits/stdc++.h> using namespace std; const int N=15000,mod=1e4; int a[N+10]={0,1,1}; int t,n; int main(){ for(int i=3;i<N;i++){ a[i]=(a[i-1]+a[i-2])%mod; } scanf("%d",&t); while(t--){ scanf("%d",&n); printf("%d\n",a[n-(n-1)/N*N]); } }