『解題報告』數學 - Standard Deviation
Information
Time Limit | 3000ms |
Memory Limit | / |
Operating System | Linux |
Source
Speciality
UVA-10886
vjudge-UVA10886 cnvjudge-UVA10886 洛谷-UVA10886
Problem
獲得途徑2
前往OJ查看題面
翻譯自行處理
ps:懶癌晚期,就不詳細展示題目了,請諒解
Status
Solution
這道題其實沒有什麼難度,只需要乖乖用數據生成器生成數據,再直接進行計算就可以了。但是要注意數據類型。
代碼如下:
#include<cstdio>
#include<iostream>
#include<climits>
#include<cmath>
using namespace std;
int n;
long double num[10000012];
long double X,ans;
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;
cin>>t;
for(int x=1;x<=t;x++)
{
X=0;
ans=0;
cin>>n>>seed;
for(int i=1;i<=n;i++)
num[i]=gen(),X+=num[i];
X/=n;
for(int i=1;i<=n;i++)
ans+=pow((num[i]-X),2);
ans/=n;
ans=sqrt(ans*1.0);
printf("Case #%d: %.5Lf\n",x,ans);
}
}