Skip to content

Commit abeeba4

Browse files
authored
math
1 parent c70ba6a commit abeeba4

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

CSA/Amusement Park.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//category : math
2+
#include <stdio.h>
3+
int T, A;
4+
double p[1002][1002];
5+
double e[1002][1002];
6+
7+
int main(){
8+
int i,j;
9+
int pij;
10+
double st = 1.f;
11+
for (scanf("%d%d", &T, &A), i = 1; i <= T; i++){
12+
for (j = 1; j <= A; j++){
13+
scanf("%d", &pij);
14+
p[i][j] = pij / 100.f;
15+
}
16+
}
17+
for (i = 1; i <= T; i++){
18+
st = 1.f;
19+
for (j = 1; j <= A; j++){
20+
e[i][1] += st*(1.f - p[i][j])*(e[i - 1][j + 1]);
21+
e[i][1] += st;
22+
st *= p[i][j];
23+
}
24+
if (st == 1.f) printf("\n!\n");
25+
e[i][1] /= (1.f - st);
26+
e[i][A+1] = e[i][1];
27+
for (j = A; j >1; j--){
28+
e[i][j] = 1.f + p[i][j] * e[i][j + 1] + (1 - p[i][j])*e[i - 1][j + 1];
29+
}
30+
}
31+
printf("%f\n", e[T][1]);
32+
33+
34+
35+
return 0;
36+
}

0 commit comments

Comments
 (0)