-
Notifications
You must be signed in to change notification settings - Fork 0
/
429l.cpp
49 lines (40 loc) · 826 Bytes
/
429l.cpp
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
#include <cstdio>
#include <iostream>
using namespace std;
double p[200010];//1
double a[200010];//0
char c[200010];
double arr[200010];
int main ()
{
int n;
scanf("%d",&n);
int number=0;
for(int i=0; i<2*n; i++)
{
//getchar();
scanf(" %c %lf",&c[i],&a[i]);
}
p[0]=1;
for(int i=1;i<2*n;i++)
{
if(c[i]=='-') p[i]=p[i-1]-1;
else p[i]=p[i-1]+1;
}
int j=0;
arr[2*n-1]=a[2*n-1];
for(int i=2*n-2; i>=0; i--)
{
if(c[i]=='-')
{
arr[i]=(1.0/p[i-1])*a[i]+(1.0-(1.0/p[i-1]))*arr[i+1];
}
else arr[i]=arr[i+1];
}
for(int i=0; i<2*n; i++)
{
if(c[i]=='+')
printf("%.10f\n",arr[i]-a[i]);
}
return 0;
}