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 ...
随机推荐
- Textbox像百度一下实现下拉显示 z
List<string> Data = new List<string>(); string Randomstr = "功夫撒黑胡椒hcbvf蜂窝qwertyuiop ...
- linux下使用go-oci8
地址:https://github.com/wendal/go-oci8 它是 https://github.com/mattn/go-oci8 的分支. win下安装步骤参考:http://www. ...
- simpletest:一个简单的PHP试工具
1. 下载: http://simpletest.org/ .2. 下载后,只要测试文件中包含如下两个文件,就可以用了 : <?php require_once('simpletest/auto ...
- selenium python (四)键盘事件
#!/usr/bin/python# -*- coding: utf-8 -*-__author__ = 'zuoanvip' #在实际测试过程中,有时候我们需要使用tab键将焦点转移到下一个需要操作 ...
- linq数据使用
取出数据库满足条件的记录的ID,把值放到list中 ) { int userid = Convert.ToInt32(Request.Cookies["id"].Value); v ...
- MemoryMappingFile泄漏分析过程
最近项目突然收到了一个紧急的问题报告 - 用户在进行某些关键操作的时候整个软件突然就crash掉了.幸好产品继承了自动抓取dump的功能... 收到dump之后,通过windbg打开,查看相应的c ...
- Raspberry Pi上手
2013-05-21 买的树莓派终于到手了,嘿嘿.我在官方代理ICKEY买的,是英国版,B型. 上手教程可以根据Getting Started with Raspberry Pi(网上有电子版免费下载 ...
- [转]Numpy中矩阵对象(matrix)
numpy模块中的矩阵对象为numpy.matrix,包括矩阵数据的处理,矩阵的计算,以及基本的统计功能,转置,可逆性等等,包括对复数的处理,均在matrix对象中. class numpy.matr ...
- js运动 多物体运动含Json 但是里面数值不一样
<!doctype html> <html> <head> <meta charset = "utf-8"> <title&g ...
- Django中如何使用django-celery完成异步任务1(转)
原文链接: http://www.weiguda.com/blog/73/ 本篇博文主要介绍在开发环境中的celery使用,请勿用于部署服务器. 许多Django应用需要执行异步任务, 以便不耽误ht ...