Codeforces Round #146 (Div. 1) B. Let's Play Osu! dp
B. Let's Play Osu!
题目连接:
http://www.codeforces.com/contest/235/problem/B
Description
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 has pi 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 numbers p1, 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 Input
3
0.5 0.5 0.5
Sample Output
2.750000000000000
Hint
题意
有一个人在玩osu,你有p[i]的概率得到o,有1-p[i]的概率得到x
你的分数等于连续o的长度的平方和
比如ooxoooxoo的分数就是2*2+3*3+2*2 = 17
现在给你p数组,问你期望得分是多少
题解:
n^2 = 2*C(n,2) + n
根据这个来DP就简单了,我们首先对于每一个位置,算出这个位置o的期望长度L就好了
他这个点的贡献就很显然是 2 * L - p[i]
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
double p[maxn];
double ans,tmp;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lf",&p[i]);
    for(int i=1;i<=n;i++)
    {
        tmp = tmp * p[i] + p[i];
        ans += 2 * tmp;
        ans -= p[i];
    }
    printf("%.12f\n",ans);
}												
											Codeforces Round #146 (Div. 1) B. Let's Play Osu! dp的更多相关文章
- Codeforces Round #267 (Div. 2) C. George and Job(DP)补题
		
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...
 - Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
		
A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...
 - Codeforces Round #146 (Div. 2)
		
A. Boy or Girl 模拟题意. B. Easy Number Challenge 筛素数,预处理出\(d_i\). 三重循环枚举. C. LCM Challenge 打表找规律. 若\(n\ ...
 - Codeforces Round #146 (Div. 1) C - Cyclical Quest  后缀自动机+最小循环节
		
#include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk mak ...
 - Codeforces Round #343 (Div. 2) C. Famil Door and Brackets dp
		
C. Famil Door and Brackets 题目连接: http://www.codeforces.com/contest/629/problem/C Description As Fami ...
 - Codeforces Round #130 (Div. 2) C - Police Station 最短路+dp
		
题目链接: http://codeforces.com/problemset/problem/208/C C. Police Station time limit per test:2 seconds ...
 - Codeforces Round #336 (Div. 2) C. Chain Reaction set维护dp
		
C. Chain Reaction 题目连接: http://www.codeforces.com/contest/608/problem/C Description There are n beac ...
 - Codeforces Round #479 (Div. 3)      F. Consecutive Subsequence    (简单dp)
		
题目:https://codeforces.com/problemset/problem/977/F 题意:一个序列,求最长单调递增子序列,但是有一个要求是中间差值都是1 思路:dp,O(n)复杂度, ...
 - Codeforces Round #396 (Div. 2) C. Mahmoud and a Message dp
		
C. Mahmoud and a Message 题目连接: http://codeforces.com/contest/766/problem/C Description Mahmoud wrote ...
 
随机推荐
- 【转】linux之tune2fs命令
			
转自:http://czmmiao.iteye.com/blog/1749232 tune2fs简介 tune2fs是调整和查看ext2/ext3文件系统的文件系统参数,Windows下面如果出现意外 ...
 - 利用 Jquery Deferred 异步你的程序
			
最近在做公司QA系统改造时,有这样的一个场景. QA系统中有些数据项需要从JIRA平台(一个国外项目与事务跟踪工具)中获取,JIRA平台提供了很完善的Rest API. 现在的要求是,在QA系统中提交 ...
 - VC++2010配置使用MySQL5.6
			
0.前提 安装后的文件概览 编译器: VC++2010 MySQL版本:MySQL5.6.19 for win64 Connector版本:connector c++ 1.1.3 在VS2010 ...
 - 书签(Bookmarks)
			
工作台允许使用者在文件中创建书签,通过这些书签,使用者可以从书签视图里快速打开这些文件,并跳转到相应的行. (1)在编辑器左边灰色的区域里单击鼠标右键,在弹出的菜单里选择“Add Bookmark.. ...
 - TopFreeTheme精选免费模板【20130701.特别版】
			
今天我们整理了16款WordPress和Joomla的最新主题.它们都是来自Themeforest,RocketTheme,YooTheme以及TemPlaza的高质量主题,赶快收藏起来吧. Este ...
 - Arduino+RFID RC522 +继电器
			
博客园的第一篇博文就献给Arduino了.不知道能不能坚持自己喜欢的并且记录下来. 起码是个好的开始. 想实现一卡通代替钥匙开启电动车. 简单的原理,通过RC522模块读取一卡通的序列号,在程序中进行 ...
 - mongodb使用中遇到的问题汇总
			
1. 每次重新打开mongo,都会显示:forked process:xxxx ,然后用 find -name mongod.lock 进行搜索,发现在 ./var/lib/mongodb/ 目录下又 ...
 - 使用Eclipse的几个必须掌握的快捷方式(能力工场小马哥收集)
			
“工若善其事,必先利其器”,感谢Eclipse,她 使我们阅读一个大工程的代码更加容易,在阅读的过程中,我发现掌握几个Eclipse的快捷键会使阅读体验更加流畅,写出来与诸君分享,欢迎补充. 1. C ...
 - 预定义宏_GNUC_    _MSC_VER
			
一.预定义__GNUC__宏 1 __GNUC__ 是gcc编译器编译代码时预定义的一个宏.需要针对gcc编写代码时, 可以使用该宏进行条件编译. 2 __GNUC__ 的值表示gcc的版本.需要针对 ...
 - mysql系统表加trigger和对特定的库禁用 DDL 语句
			
给 mysql 系统表加上 trigger 1 Reply 默认情况下,mysql 是不能给系统表,例如 mysql.user 加上触发器的.会提示 ERROR 1465 (HY000): Trigg ...