You're playing a game called Osu! Here's a simplified version of it. There are n clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be encoded as a sequence of n characters "O" and "X".

Using the play sequence you can calculate the score for the play as follows: for every maximal consecutive "O"s block, add the square of its length (the number of characters "O") to the score. For example, if your play can be encoded as "OOXOOOXXOO", then there's three maximal consecutive "O"s block "OO", "OOO", "OO", so your score will be 22 + 32 + 22 = 17. If there are no correct clicks in a play then the score for the play equals to 0.

You know that the probability to click the i-th (1 ≤ i ≤ n) click correctly is pi. In other words, the i-th character in the play sequence haspi probability to be "O", 1 - pi to be "X". You task is to calculate the expected score for your play.

Input

The first line contains an integer n (1 ≤ n ≤ 105) — the number of clicks. The second line contains n space-separated real numbersp1, p2, ..., pn (0 ≤ pi ≤ 1).

There will be at most six digits after the decimal point in the given pi.

Output

Print a single real number — the expected score for your play. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Sample test(s)
input
3
0.5 0.5 0.5
output
2.750000000000000
input
4
0.7 0.2 0.1 0.9
output
2.489200000000000
input
5
1 1 1 1 1
output
25.000000000000000
Note

For the first example. There are 8 possible outcomes. Each has a probability of 0.125.

  • "OOO"  →  32 = 9;
  • "OOX"  →  22 = 4;
  • "OXO"  →  12 + 12 = 2;
  • "OXX"  →  12 = 1;
  • "XOO"  →  22 = 4;
  • "XOX"  →  12 = 1;
  • "XXO"  →  12 = 1;
  • "XXX"  →  0.

So the expected score is 

题解:http://www.w2bc.com/Article/20411

code:

 #include<cstdio>
using namespace std;
int n;
double ans,tmp,x;
int main(){
scanf("%d",&n);
for (int i=;i<=n;i++) scanf("%lf",&x),tmp*=x,ans+=*tmp+x,tmp+=x;
printf("%.10lf\n",ans);
return ;
}

PS:好久没有写这么短的代码了

codeforces 235 B. Let's Play Osu!的更多相关文章

  1. [codeforces 235]A. LCM Challenge

    [codeforces 235]A. LCM Challenge 试题描述 Some days ago, I learned the concept of LCM (least common mult ...

  2. codeforces 235 B lets play osu!

    cf235B 一道有意思的题.(据说是美少女(伪)计算机科学家出的,hh) 根据题目要求,就是求ni^2的和. 而n^2=n*(n-1)+n; n*(n-1)=C(n,2)*2: 所以∑ai^2=∑a ...

  3. [ BZOJ 4318 & 3450 / CodeForces 235 B ] OSU!

    \(\\\) \(Description\) 一共进行\(N\)次操作,生成一个长度为\(N\)的\(01\)序列,成功对应\(1\),失败对应\(0\),已知每一次操作的成功率\(p_i\). 在这 ...

  4. 【codeforces 235B】Let's Play Osu!

    [题目链接]:http://codeforces.com/problemset/problem/235/B [题意] 让你玩一个游戏,游戏结果由一个长度为n的01字符组成; 这个结果的分数与连续的1的 ...

  5. codeforces 235 div2 C Team

    题目:http://codeforces.com/contest/401/problem/C 题意:n个0,m个1,求没有00或111的情况. 这么简单的题..... 做题的时候脑残了...,今天,贴 ...

  6. Codeforces 235B Let&#39;s Play Osu! 概率dp(水

    题目链接:点击打开链接 给定n表示有n个格子 以下每一个格子为O的概率是多少. 对于一段连续 x 个O的价值就是 x*x ; 问: 获得的价值的期望是多少. 思路: 把公式拆一下.. #include ...

  7. codeforces 235 div2 B. Sereja and Contests

    Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good ...

  8. codeforces 235 div2 A. Vanya and Cards

    Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer ...

  9. Codeforces 235 E Number Challenge

    Discription Let's denote d(n) as the number of divisors of a positive integer n. You are given three ...

随机推荐

  1. Registering Shell Extension Handlers

    最近在做Windows shell extension 的开发工作,对shell extension handler的注册机制有点疑问,以下摘自MSDN:http://msdn.microsoft.c ...

  2. Jenkins 学习资料

    学习资料: iTech's Blog: Jenkins 入门总结 爱自己: 18篇博客 阳光温暖了心情: 17 篇博客 官网 参考: 构建基于Jenkins + Github的持续集成环境 CI持续集 ...

  3. M - 非常可乐

    很明显看出来的广搜题目,不过因为有3个杯子相互倾倒,所以会产生6种倒发,比较冗杂,不过应该可以构造一个数组来解决这个问题,试试看吧 ////////////////////////////////// ...

  4. 【Cocos2d-X开发学习笔记】第26期:游戏背景之滚动地图背景(CCParallaxNode)的使用

    本系列学习教程使用的是cocos2d-x-2.1.4(最新版为3.0alpha0-pre) ,PC开发环境Windows7,C++开发环境VS2010 在现实生活中,当我们身处一辆快速行驶的车上,用眼 ...

  5. Azkaban2配置过程

    Azkaban2配置过程 azkaban2所需环境:jdk1.6.ant.jetty.hadoop.ssl证书 通过http://azkaban.github.io/azkaban2/download ...

  6. Mysql学生管理系统:表的建立,外键一对多,多对多关系,中间关联表的建立

    学生管理系统 管理员注册/登录/注销 注册班级(班级详细信息) 注册学生信息 查看班级信息/查看老师资料 教师注册/注销  查看教师资料  查看学生资料  根据名称/班级/ 查看学生详细信息--支持模 ...

  7. 【转】AngularJS 日期格式化 字典

    本地化日期格式化: ({{time|date:'medium' }})Apr 14, 2016 4:40:08 PM ({{time | date:'short' }})4/14/16 4:40 PM ...

  8. .net自定义控件

    一.[.net自定义控件]TextBox控件重写 之NumTextBox 参考博客:http://www.yongfa365.com/Item/NumTextBox.html 二.[.net自定义控件 ...

  9. ie11只能用管理员身份打开解决办法

    解决IE11只能用管理员身份运行的问题 不知道大家有没有遇到这种情况,在毫不知情的情况下 IE11 突然打不开了,必须要用管理员身份运行才可以打开,而且重置浏览器这个方法也不奏效. 今天本人也遇到了, ...

  10. 文件标准IO的mode

    1. r / r+ 是不创建文件,前者只读,后者可读写 2. w / w+ 是能创建文件,并且把文件置空,前者只写,后者可读写 3. a / a+ 是能创建文件,但不置空文件,在文件末尾写,前者只写, ...