HDU 4986 Little Pony and Alohomora Part I(递推+犹拉常数)
2014-09-01 15:03
495 查看
HDU 4986 Little Pony and Alohomora Part I
题目链接题意:一些钥匙随机放在箱子里,现在问打开次数期望
思路:每种方式相当于一个置换的循环个数,那么考虑f[i]为i个箱子的情况,f[i + 1]要么就是放在最后多一个循环,要么就是插入中间循环个数不变,对应的转移为f[i + 1] = (f[i] + 1) / i + f[i] * (i - 1) / i 化简得到f[i] = f[i - 1] + 1 / i
这个式子i越大,越趋近lni + C,这个C为犹拉常数,所以先递推出数字小的情况,大的就直接计算
代码:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 1000005;
const double sb = 0.577215664901;
int n;
double ans
;
int main() {
for (int i = 1; i < N; i++)
ans[i] = ans[i - 1] + 1.0 / i;
while (~scanf("%d", &n)) {
if (n >= N) printf("%.4lf\n", sb + log(n * 1.0) + 1.0 / (2 * n));
else printf("%.4lf\n", ans
);
}
return 0;
}
相关文章推荐
- hdu 4986 Little Pony and Alohomora Part I(递推)
- 【CUGBACM15级BC第7场 B】hdu 4986 Little Pony and Alohomora Part I
- BestCoder7 1002 Little Pony and Alohomora Part I(hdu 4986) 解题报告
- hdu 4986 Little Pony and Alohomora Part I(找规律,欧拉常数)
- HDU 4986 Little Pony and Alohomora Part I(递推+欧拉常数)
- 【数论】 HDOJ 4986 Little Pony and Alohomora Part I
- 【HDOJ】4986 Little Pony and Alohomora Part I
- HDU4986 Little Pony and Alohomora Part I
- 杭电 bestcoder round#7 1002 Little Pony and Alohomora Part I
- hdu 4985 Little Pony and Permutation
- HDU 4985 Little Pony and Permutation(置换)
- hdu 4985 Little Pony and Permutation(水题)
- HDU 4985-Little Pony and Permutation(模拟置换)
- [BestCoder Round #7] hdu 4985 Little Pony and Permutation (找循环节)
- 【HDU】4985 Little Pony and Permutation 置换群
- HDU 4985 Little Pony and Permutation(数学 置换群)
- HDU 4985 Little Pony and Permutation(简单模拟)
- 【CUGBACM15级BC第7场 A】hdu 4985 Little Pony and Permutation
- BestCoder7 1001 Little Pony and Permutation(hdu 4985) 解题报告
- hdu 4988 Little Pony and Boast Busters ( 树状数组+treap )