-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva10883.cpp
More file actions
43 lines (37 loc) · 816 Bytes
/
uva10883.cpp
File metadata and controls
43 lines (37 loc) · 816 Bytes
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
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int MAX_N = 50007;
const double EPS = 1e-8;
double a[MAX_N], _lg[MAX_N];
int dcmp(double x) {
if (fabs(x) < EPS)
return 0;
return x > EPS ? 1 : -1;
}
int main() {
int cas = 0;
int T;
scanf("%d", &T);
while(T-- > 0) {
int n;
scanf("%d", &n);
--n;
for (int i = 0; i <= n; ++i) {
scanf("%lf", &a[i]);
}
_lg[0] = 0;
for (int i = 1; i <= n; ++i) {
_lg[i] = _lg[i - 1] + log10(n - i + 1) - log10(i);
}
double ans = 0;
double end = log10(2) * n;
for (int i = 0; i <= n; ++i) {
if (dcmp(a[i]) < 0) ans -= pow(10, _lg[i] - end + log10(-a[i]));
else if (dcmp(a[i]) > 0) ans += pow(10, _lg[i] - end + log10(a[i]));
}
printf("Case #%d: %.3f\n" , ++cas, ans);
}
return 0 ;
}