Test instructions: The standard deviation (1 <= n <= 10000000,0 <= seed < 2^64) for the first n of the value generated by the following function.
Long Double Gen () { staticconstlongdoublelongdouble ) 1.0 /(1ll<<1* = seed; return seed * Z;
Write the formula of the variance, then expand all the squares of the numerator, merge, simplify, and then the variance is
∑ (xi^2)/n + (∑ (xi)/n) ^ 2
The standard Chakaigen number can be.
The complexity is O (n) and can withstand within 3s.
The code is as follows:
#include <cstdio>#include<cstring>#include<cctype>#include<cstdlib>#include<cmath>#include<iostream>#include<sstream>#include<iterator>#include<algorithm>#include<string>#include<vector>#include<Set>#include<map>#include<deque>#include<queue>#include<stack>#include<list>#defineFin freopen ("In.txt", "R", stdin)#defineFout freopen ("OUT.txt", "w", stdout)#definePR (x) cout << #x << ":" << x << ""#definePRLN (x) cout << #x << ":" << x << Endl#defineMin (A, B) a < b? A:b#defineMax (A, B) a < b? B:atypedefLong Longll;typedef unsignedLong LongLlu;Const intInt_inf =0x3f3f3f3f;Const intInt_m_inf =0x7f7f7f7f;Constll ll_inf =0x3f3f3f3f3f3f3f3f;Constll ll_m_inf =0x7f7f7f7f7f7f7f7f;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-6;Const intDr[] = {0,0, -1,1, -1, -1,1,1};Const intDc[] = {-1,1,0,0, -1,1, -1,1};Constll MOD = 1e9 +7;using namespacestd;#defineNdebug#include<cassert>Const intMAXN = -+Ten;Const intMaxt =10000+Ten; llu seed;intN, T;Long DoubleGen () {Static Const Long DoubleZ = (Long Double)1.0/(1ll << +); Seed>>= -; Seed&= (1llu << +) -1; Seed*=seed; returnSeed *Z;}intMain () {intKase =0; scanf ("%d", &T); while(t--) {scanf ("%d%llu", &n, &seed); DoubleSUM1 =0.0, sum2 =0.0; for(inti =0; I < n; ++i) { DoubleTMP =Gen (); Sum1+ = tmp *tmp; Sum2+=tmp; } sum1/= N; Sum2/=N; printf ("Case #%d:%.5lf\n", ++kase, sqrt (sum1-sum2 *sum2)); } return 0;}
Uva-10886-standard Deviation (simplification + violence)