codeforces 235 B. Let's Play Osu!
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.
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.
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.
3
0.5 0.5 0.5
2.750000000000000
4
0.7 0.2 0.1 0.9
2.489200000000000
5
1 1 1 1 1
25.000000000000000
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!的更多相关文章
- [codeforces 235]A. LCM Challenge
[codeforces 235]A. LCM Challenge 试题描述 Some days ago, I learned the concept of LCM (least common mult ...
- 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 ...
- [ BZOJ 4318 & 3450 / CodeForces 235 B ] OSU!
\(\\\) \(Description\) 一共进行\(N\)次操作,生成一个长度为\(N\)的\(01\)序列,成功对应\(1\),失败对应\(0\),已知每一次操作的成功率\(p_i\). 在这 ...
- 【codeforces 235B】Let's Play Osu!
[题目链接]:http://codeforces.com/problemset/problem/235/B [题意] 让你玩一个游戏,游戏结果由一个长度为n的01字符组成; 这个结果的分数与连续的1的 ...
- codeforces 235 div2 C Team
题目:http://codeforces.com/contest/401/problem/C 题意:n个0,m个1,求没有00或111的情况. 这么简单的题..... 做题的时候脑残了...,今天,贴 ...
- Codeforces 235B Let's Play Osu! 概率dp(水
题目链接:点击打开链接 给定n表示有n个格子 以下每一个格子为O的概率是多少. 对于一段连续 x 个O的价值就是 x*x ; 问: 获得的价值的期望是多少. 思路: 把公式拆一下.. #include ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- GitLib
http://www.360doc.com/content/15/0603/14/21631240_475362133.shtml 原文 http://blog.csdn.net/williamwan ...
- Linux用户与用户组的详解
1,用户和用户组文件 在linux中,用户帐号,用户密码,用户组信息和用户组密码均是存放在不同的配置文件中的. 在linux系统中,所创建的用户帐号和其相关信息(密码除外)均是存放在/etc/ ...
- Android ViewPager PagerAdapter 图片轮播
ViewPager类直接继承了ViewGroup类,所有它是一个容器类,可以在其中添加其他的View类. ViewPager类需要一个PagerAdapter适配器类给它提供数据. ViewPager ...
- SDN:软件定义网络
近期高级网络课的小组任务是在老师给定的范围内自选方向主题研究并做展示报告.我们组选了sdn.原以为这东西会是工业界无人问津的概念化产品,Google了一下却发现事实上sdn挺火的,因为它可能带来的可扩 ...
- innode 节点
[root@localhost soft]# ls -i tt1 tt2 xx.c [root@localhost soft]# stat tt1 File: `tt1' Size: 4096 Blo ...
- 汉诺塔III 递推题
题目描述: 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到大顺序串着由64个圆盘构成的塔.目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动 ...
- Codeforces 245G Suggested Friends - 交集set_intersection()
一些人互相是朋友(无向图连一条无向边),现在要添加一个推荐朋友的功能,如果对于x,有y,x与y不是朋友,但是y和x有共同的朋友,并且共同的朋友最多,那么y可以推荐给x.问对于每一个人,有多少人值得推荐 ...
- java org.apache.struts.taglib.html.BEAN 没有找到
index.jsp <body> <a href="login2.do">登陆(struts标签)</a><br> </bod ...
- 安装ZendDebugger 调试php
一直懒得装断点调试工具,平时调试就用echo var_dump debug_print_backtrace 搞搞. 今天同事装了个xdebug,看着眼馋.于是想自己也装一个,由于平时用zend stu ...
- IIS支持APK/ISO文件下载的方法
默认把安卓手机应用或游戏的apk格式文件上传到服务器空间是不能直接下载的,这是因为IIS的默认MIME类型中没有.apk文件,所以无法下载.@VCOO 既然.apk无法下载是因为没有MIME,那么添加 ...