题目链接:幻象
同洛谷Let’s Play Osu!
分析
设
p
[
i
]
p[i]
p[i]为第
i
i
i秒幻象的持续时间的期望
p
[
i
]
=
(
p
[
i
−
1
]
+
1
)
∗
a
[
i
]
/
100
p[i]=(p[i-1] + 1)*a[i]/100
p[i]=(p[i−1]+1)∗a[i]/100
设
f
[
i
]
f[i]
f[i]为前
i
i
i秒的答案。
f
[
i
]
=
f
[
i
−
1
]
+
(
(
p
[
i
−
1
]
+
1
)
2
–
p
[
i
−
1
]
2
)
∗
a
[
i
]
/
100
f[i]=f[i-1]+((p[i-1] + 1)^2–p[i-1]^2)*a[i]/100
f[i]=f[i−1]+((p[i−1]+1)2–p[i−1]2)∗a[i]/100
f
[
i
]
=
f
[
i
−
1
]
+
(
2
∗
p
[
i
−
1
]
+
1
)
∗
a
[
i
]
/
100
;
f[i]=f[i-1]+(2*p[i-1]+1)*a[i]/100;
f[i]=f[i−1]+(2∗p[i−1]+1)∗a[i]/100;
上代码
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
using namespace std;
int n;
int a[1000010];
double p[1000001],f[1000001];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++)
{
p[i]=(p[i-1]+1)*a[i]/100;
}
for(int i=1;i<=n;i++)
{
f[i]=f[i-1]+(2*p[i-1]+1)*a[i]/100;
}
printf("%.1f",f[n]);
return 0;
}