期望题,维护期望和平方的期望就可以计算
#include <cstdio> #include <memory.h> #include <cstring> #include <algorithm> #include <cstdlib> #include <cctype> using namespace std; void read(double &num) { num=0; bool after=0; double bei=1; char tmpc; do { tmpc=getchar(); } while (!isdigit(tmpc)); while (isdigit(tmpc)) { if (after) { bei/=10; num=num+(tmpc-'0')*bei; } else num=num*10+tmpc-'0'; tmpc=getchar(); if (tmpc=='.') { after=1; tmpc=getchar(); } } } int main() { register int n; scanf("%d",&n); register double f = 0,g = 0,ans = 0, p; while (n--) { read(p); ans += (3*f+3*g+1)*p; g = (g+2*f+1) * p; f = (f+1) * p; } printf("%.1f\n",ans); }