分数序列和
题目链接: http://exercise.acmcoder.com/online/online_judge_ques?ques_id=3371&konwledgeId=40
解题思路: 直接求解就可以了。
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 typedef long long LL; 5 const int MAXN=100005; 6 const LL MON7 = 1e9+7; 7 8 unsigned long long f[92]; 9 double ans[92]; 10 11 void init() 12 { 13 f[0]=1; 14 f[1]=1; 15 for (int i=2;i<=91;++i) f[i]=f[i-1]+f[i-2]; 16 // for (int i=2;i<=91;++i) printf("%llu\n",f[i]); 17 ans[0]=0; 18 for (int i=1;i<=90;++i) ans[i]=ans[i-1]+1.0*f[i+1]/f[i]; 19 // for (int i=1;i<=90;++i) printf("%.8f\n",ans[i]); 20 } 21 int main() 22 { 23 #ifndef ONLINE_JUDGE 24 freopen("test.txt","r",stdin); 25 #endif // ONLINE_JUDGE 26 init(); 27 int Case; 28 int n; 29 scanf("%d",&Case); 30 while (Case--) 31 { 32 scanf("%d",&n); 33 printf("%.4f\n",ans[n]); 34 } 35 return 0; 36 }