HDU 4986 little pony and Alohomora Part I
Question Link
Some keys are randomly stored in the box. Now I want to open the keys.
Idea: each method is equivalent to the number of replicas. If f [I] is an I box, F [I + 1] is either placed in the last loop, either the number of inserted intermediate loops remains unchanged, and the corresponding transfer is f [I + 1] = (F [I] + 1)/I + F [I] * (I-1) /I simplification to obtain f [I] = f [I-1] + 1/I
The larger the subi is, the closer it approaches lni + C. This C is a constant of the Jura. Therefore, when the number is small, it is directly calculated.
Code:
# Include <cstdio> # include <cstring> # include <cmath> # include <algorithm> using namespace STD; const int n = 1000005; const double sb = 0.577215664901; int N; double ans [N]; 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); else printf (" %. 4lf \ n ", ANS [N]);} return 0 ;}
HDU 4986 little pony and Alohomora Part I (recursive + constant)