forked from sukhoeing/aoapc-bac2nd-keys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVa10886.cc
69 lines (64 loc) · 1.35 KB
/
UVa10886.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// UVa10886 Standard Deviation
// 陈锋
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>
using namespace std;
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)
typedef long long LL;
typedef unsigned long long ULL;
struct Gen {
ULL seed;
ULL gen() {
seed >>= 16;
seed &= (1ULL << 32) - 1;
seed *= seed;
return seed;
}
};
typedef long double LD;
const LD Z = (LD)1.0 / (1LL << 32);
int main() {
int T, N;
ULL seed;
scanf("%d", &T);
_rep(t, 1, T) {
Gen gen;
scanf("%d%llu", &N, &(seed));
gen.seed = seed;
LD sq = 0, m = 0;
_for(i, 0, N) {
auto g = gen.gen();
LD x = g * Z;
printf("%llx, ", g);
if (g == 0) {
break;
} else if (g == (1ULL << 32)) {
sq += x * x * (N - i), m += x * (N - i);
break;
} else {
sq += x * x, m += x;
}
}
puts("");
m /= N, sq /= N;
LD ans = sqrt(sq - m * m);
printf("Case #%d: %.5Lf\n", t, ans);
}
}
// 19747300 10886 Standard Deviation Accepted C++11 0.000 2017-07-26 15:23:15