hdu 4986 Little Pony and Alohomora Part I(递推)
2014-08-31 22:01
302 查看
题目链接:hdu 4986 Little Pony and Alohomora Part I
题目大意:给定若干个箱子,每个箱子中装着一把钥匙,问最少要敲开多少个箱子才能打开所有箱子。
解题思路:需要敲开的次数即为整个序列循环的个数,知道这点就很容易得到f(i)=f(i−1)+1i,然后对于n小的情况,用递推即可,对于n大的情况,用log函数近似处理。
题目大意:给定若干个箱子,每个箱子中装着一把钥匙,问最少要敲开多少个箱子才能打开所有箱子。
解题思路:需要敲开的次数即为整个序列循环的个数,知道这点就很容易得到f(i)=f(i−1)+1i,然后对于n小的情况,用递推即可,对于n大的情况,用log函数近似处理。
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int maxn = 1e6; double p[maxn+5]; void init () { p[1] = 1; for (int i = 2; i <= maxn; i++) p[i] = p[i-1] + 1.0 / i; } int main () { init(); int n; while (scanf("%d", &n) == 1) { printf("%.4lf\n", n >= maxn ? 0.577215664901 + log((double)n) : p ); } 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 4988 Little Pony and Boast Busters ( 树状数组+treap )
- hdu 4985 Little Pony and Permutation(水题)
- HDU 4985-Little Pony and Permutation(模拟置换)
- 【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) 解题报告
- [BestCoder Round #7] hdu 4985 Little Pony and Permutation (找循环节)