Uva-10886-standard Deviation (simplification + violence)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.