UVA 10886 - Standard Deviation(暴力)
题目链接 https://cn.vjudge.net/problem/UVA-10886
【题意】
给你一个随机数发生器,输入seed的初始值,你的任务是求出它得到的前n个随机数的标准差,保留5位小数(1<=n<=1e7,0<=seed<2^64)
unsigned long long seed;
long double gen(){
static const long double Z = ( long double )1.0 / (1LL<<32);
seed >>= 16;
seed &= ( 1ULL << 32 ) - 1;
seed *= seed;
return seed * Z;
}
【思路】
直接用题目的代码暴力算即可
#include<bits/stdc++.h>
using namespace std;
const int maxn=10000005;
int n;
long double a[maxn];
unsigned long long seed;
long double gen(){
static const long double Z = ( long double )1.0 / (1LL<<32);
seed >>= 16;
seed &= ( 1ULL << 32 ) - 1;
seed *= seed;
return seed * Z;
}
int main(){
int T;
scanf("%d",&T);
for(int kase=1;kase<=T;++kase){
scanf("%d%llu",&n,&seed);
long double ave=0;
for(int i=0;i<n;++i){
a[i]=gen();
ave+=a[i];
}
ave/=n;
long double ans=0;
for(int i=0;i<n;++i){
ans+=(a[i]-ave)*(a[i]-ave);
}
ans/=n;
ans=sqrt(ans*1.0);
printf("Case #%d: %.5Lf\n",kase,ans);
}
return 0;
}