题意:下面是一个随机数发生器。输入seed的初始值,你的任务是求出它得到的前n个随机数标准差,保留小数点后5位(1<=n<=10000000,0<=seed<264)。

分析:方差的式子最好化简一下再计算,否则按部就班,提前算出平均数,代入计算会产生精度误差导致WA。

化简方法:

将上式全部展开,并合并同类项,可得∑(xi2) / n - m2,m是平均数。求标准差,开根号即可。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b) {
if(fabs(a - b) < eps) return 0;
return a < b ? -1 : 1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1e7 + 10;
const int MAXT = 10000 + 10;
using namespace std;
ULL 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);
int kase = 0;
while(T--){
int n;
scanf("%d%llu", &n, &seed);
double sum1 = 0;
double sum2 = 0;
for(int i = 0; i < n; ++i){
double tmp = 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 (标准差)(数论)的更多相关文章

  1. UVA 10886 Standard Deviation

    https://vjudge.net/problem/UVA-10886 计算标准差 碰到这种题将式子展开 #include<cmath> #include<cstdio> / ...

  2. range|Sample Standard Deviation|标准差几何意义

    Measures of Variation 方差:measures of variation or measures of spread 源于range发现range不足以评估整个set(因为只用到l ...

  3. 标准差(Standard Deviation) 和 标准误差(Standard Error)

    本文摘自 Streiner DL.Maintaining standards: differences between the standard deviation and standarderror ...

  4. 标准差(standard deviation)和标准误差(standard error)你能解释清楚吗?

    by:ysuncn(欢迎转载,请注明原创信息) 什么是标准差(standard deviation)呢?依据国际标准化组织(ISO)的定义:标准差σ是方差σ2的正平方根:而方差是随机变量期望的二次偏差 ...

  5. 标准差(standard deviation)和标准错误(standard error)你能解释一下?

    by:ysuncn(欢迎转载,转载请注明原始消息) 什么是标准差(standard deviation)呢?依据国际标准化组织(ISO)的定义:标准差σ是方差σ2的正平方根.而方差是随机变量期望的二次 ...

  6. 方差(variance)、标准差(Standard Deviation)、均方差、均方根值(RMS)、均方误差(MSE)、均方根误差(RMSE)

    方差(variance).标准差(Standard Deviation).均方差.均方根值(RMS).均方误差(MSE).均方根误差(RMSE) 2017年10月08日 11:18:54 cqfdcw ...

  7. 均方根值(RMS)+ 均方根误差(RMSE)+标准差(Standard Deviation)

    均方根值(RMS)+ 均方根误差(RMSE)+标准差(Standard Deviation)  1.均方根值(RMS)也称作为效值,它的计算方法是先平方.再平均.然后开方. 2.均方根误差,它是观测值 ...

  8. 均方根误差(RMSE),平均绝对误差 (MAE),标准差 (Standard Deviation)

    来源:https://blog.csdn.net/capecape/article/details/78623897 RMSE Root Mean Square Error, 均方根误差是观测值与真值 ...

  9. 标准差standard deviation和标准错误standard error你能解释一下

    by:ysuncn(欢迎转载,请注明原创信息) 什么是标准差(standard deviation)呢?依据国际标准化组织(ISO)的定义:标准差σ是方差σ2的正平方根:而方差是随机变量期望的二次偏差 ...

随机推荐

  1. (3)LoraWAN:链路控制、SF BW CR

    三.Introduction on LoRaWAN options 本文件描述了一种用于可为移动的或固定在一个固定位置的电池供电的终端设备而优化的LoRaWAN™网络协议.LORA™是一个由Semte ...

  2. 解题报告:luogu P1516 青蛙的约会

    题目链接:P1516 青蛙的约会 考察拓欧与推式子\(qwq\). 题意翻译? 求满足 \[\begin{cases}md+x\equiv t\pmod{l}\\nd+y\equiv t\pmod{l ...

  3. matplotlib画图的时候显示不出中文和负号的解决办法

    import matplotlib.pyplot as pltfrom pylab import * plt.rcParams['font.sans-serif'] = ['SimHei'] #显示中 ...

  4. Day9 - D - Piggy-Bank POJ - 1384

    Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. ...

  5. redis配置文件中常用配置详解

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/suprezheng/article/de ...

  6. 吴裕雄--天生自然JAVAIO操作学习笔记:RandomAccessFile

    import java.io.File ; import java.io.RandomAccessFile ; public class RandomAccessFileDemo01{ // 所有的异 ...

  7. greenplum 存储过程 函数

    参考:https://docs.pivotal.io/search?q=function

  8. Rancher概述

    概述 What’s Rancher? Rancher是一套容器管理平台,它可以帮助组织在生产环境中轻松快捷的部署和管理容器. Rancher可以轻松地管理各种环境的Kubernetes,满足IT需求并 ...

  9. MySQL查询事务 杀死事务

    遇到 com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock 查询: SELECT * FROM inf ...

  10. P1042 字符统计

    P1042 字符统计 转跳点: