UVA - 10886 Standard Deviation (标准差)(数论)
题意:下面是一个随机数发生器。输入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 (标准差)(数论)的更多相关文章
- UVA 10886 Standard Deviation
https://vjudge.net/problem/UVA-10886 计算标准差 碰到这种题将式子展开 #include<cmath> #include<cstdio> / ...
- range|Sample Standard Deviation|标准差几何意义
Measures of Variation 方差:measures of variation or measures of spread 源于range发现range不足以评估整个set(因为只用到l ...
- 标准差(Standard Deviation) 和 标准误差(Standard Error)
本文摘自 Streiner DL.Maintaining standards: differences between the standard deviation and standarderror ...
- 标准差(standard deviation)和标准误差(standard error)你能解释清楚吗?
by:ysuncn(欢迎转载,请注明原创信息) 什么是标准差(standard deviation)呢?依据国际标准化组织(ISO)的定义:标准差σ是方差σ2的正平方根:而方差是随机变量期望的二次偏差 ...
- 标准差(standard deviation)和标准错误(standard error)你能解释一下?
by:ysuncn(欢迎转载,转载请注明原始消息) 什么是标准差(standard deviation)呢?依据国际标准化组织(ISO)的定义:标准差σ是方差σ2的正平方根.而方差是随机变量期望的二次 ...
- 方差(variance)、标准差(Standard Deviation)、均方差、均方根值(RMS)、均方误差(MSE)、均方根误差(RMSE)
方差(variance).标准差(Standard Deviation).均方差.均方根值(RMS).均方误差(MSE).均方根误差(RMSE) 2017年10月08日 11:18:54 cqfdcw ...
- 均方根值(RMS)+ 均方根误差(RMSE)+标准差(Standard Deviation)
均方根值(RMS)+ 均方根误差(RMSE)+标准差(Standard Deviation) 1.均方根值(RMS)也称作为效值,它的计算方法是先平方.再平均.然后开方. 2.均方根误差,它是观测值 ...
- 均方根误差(RMSE),平均绝对误差 (MAE),标准差 (Standard Deviation)
来源:https://blog.csdn.net/capecape/article/details/78623897 RMSE Root Mean Square Error, 均方根误差是观测值与真值 ...
- 标准差standard deviation和标准错误standard error你能解释一下
by:ysuncn(欢迎转载,请注明原创信息) 什么是标准差(standard deviation)呢?依据国际标准化组织(ISO)的定义:标准差σ是方差σ2的正平方根:而方差是随机变量期望的二次偏差 ...
随机推荐
- eclipse不能启动,An internal error occurred during: "reload maven project".
An internal error occurred during: "reload maven project". 这个错误是因为项目已经关闭,导致 导致此问题的原因是Sprin ...
- jquery源码部分分析
1.整体架构和如何辨别浏览器端和node端 自执行函数,判断在什么端,如果在浏览器端就执行factory函数 //(function(){a,b})(a,b) //jq大架构,闭包,自执行函数,传入函 ...
- PhpStorm 10.0.1破解激活步骤
1.下载破解补丁 链接:https://pan.baidu.com/s/1S4JVKiaFnCZG01MpDPaAAA 密码:c6x6 放到phpstorm安装目录下的lib文件夹下: C:\soft ...
- Windows下配置多个Git账号
1. 为什么会用多个git账号? 不同git账号对应不同代码托管平台,如:github.bitbucket.gitlab.gitee(码云)等 2个GitHub账号,用于测试(最近需求,之前没研究过g ...
- IOS UIKIT_EXTERN, __attribute__((visibility ("default"))) 是啥玩意?
问题提出 在学习IOS时候,碰到一个函数NSStringFromCGPoint (UIGeometry.h) 其原型是 UIKIT_EXTERN NSString *NSStringFromCGPoi ...
- 关于Essay写作的Tips及整体讲解
Essay,相信在国外留学的小伙伴们都不会陌生,无论你是读本科还是硕士,甚至是读中学,都要经历Essay写作,也就是我们的小论文.那么,无论你是开始了英国学校的学习还是将要开始,你对Essay写作的了 ...
- 简单模拟IOC容器:为添加了@Autowired的属性赋值(初始值)
创建@Autowired注解 package com.zzj.test; import java.lang.annotation.ElementType; import java.lang.annot ...
- git客户端出现libpng warning: iCCP: known incorrect sRGB profile
在关闭gitk窗口的时候,会出现一系列的 libpng warning: iCCP: known incorrect sRGB profilelibpng warning: iCCP: known ...
- Spring中获取web项目的根目录
spring 在 org.springframework.web.util 包中提供了几个特殊用途的 Servlet 监听器,正确地使用它们可以完成一些特定需求的功能; WebAppRootListe ...
- msf生成软件
生成软件后门程序的命令 win7获取 生成内网软件 启动kali上的http服务 systemctl start apache2 开始msf控制台 msfconsole 使用监听模块 并查看配置 s ...