题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4318

4318: OSU!

Time Limit: 2 Sec  Memory Limit: 128 MB
Submit: 374  Solved: 294
[Submit][Status][Discuss]

Description

osu 是一款群众喜闻乐见的休闲软件。 
我们可以把osu的规则简化与改编成以下的样子: 
一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1个长度为n的01串。在这个串中连续的 X个1可以贡献X^3 的分数,这x个1不能被其他连续的1所包含(也就是极长的一串1,具体见样例解释) 
现在给出n,以及每个操作的成功率,请你输出期望分数,输出四舍五入后保留1位小数。 
 
 

Input

第一行有一个正整数n,表示操作个数。接下去n行每行有一个[0,1]之间的实数,表示每个操作的成功率。 
 
 

Output

只有一个实数,表示答案。答案四舍五入后保留1位小数。 
 

Sample Input

3
0.5
0.5
0.5

Sample Output

6.0

HINT

【样例说明】 
000分数为0,001分数为1,010分数为1,100分数为1,101分数为2,110分数为8,011分数为8,111分数为27,总和为48,期望为48/8=6.0 
N<=100000

Source

考虑每一位对答案的贡献为f[i];则f[i]=p[i]*(3*e1[i-1]+3*e2[i-1]+1),e1[i]表示到i位连续1的期望,e2[i]就是平方的期望。把每一位的贡献加起来就是答案。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define maxn 100005
using namespace std;
int n;
typedef double ld;
ld ans,p[maxn],f[maxn],e1[maxn],e2[maxn];
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%lf",&p[i]);
for(int i=;i<=n;i++){
f[i]=p[i]*(+*e1[i-]+*e2[i-]);
e1[i]=p[i]*(e1[i-]+);e2[i]=p[i]*(e2[i-]+*e1[i-]+);
}
for(int i=;i<=n;i++)ans+=f[i];
printf("%.1lf\n",ans);
return ;
}

题目链接:http://codeforces.com/problemset/problem/235/B

B. Let's Play Osu!
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
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 

其实和上一题一样,就是变成平方了而已。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define maxn 100005
using namespace std;
int n;
typedef double ld;
ld ans,p[maxn],f[maxn],e1[maxn];
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%lf",&p[i]);
for(int i=;i<=n;i++){
f[i]=p[i]*(+*e1[i-]);
e1[i]=p[i]*(e1[i-]+);
}
for(int i=;i<=n;i++)ans+=f[i];
printf("%.12lf\n",ans);
return ;
}

bzoj4318: OSU!&&CF235BLet's Play Osu!的更多相关文章

  1. [ACM_水题] ZOJ 3712 [Hard to Play 300 100 50 最大最小]

    MightyHorse is playing a music game called osu!. After playing for several months, MightyHorse disco ...

  2. ZOJ3712:Hard to Play

    MightyHorse is playing a music game called osu!. After playing for several months, MightyHorse disco ...

  3. 标准差分进化算法matlab程序实现(转载)

    标准差分进化算法matlab程序实现 自适应差分演化算法方面的Matlab和C++代码及论文 差分进化算法 DE-Differential Evolution matlab练习程序(差异演化DE) [ ...

  4. ZCMU训练赛-H(模拟)

    H - Hard to Play   MightyHorse is playing a music game called osu!. After playing for several months ...

  5. 【BZOJ4318】OSU! 期望DP

    [BZOJ4318]OSU! Description osu 是一款群众喜闻乐见的休闲软件.  我们可以把osu的规则简化与改编成以下的样子:  一共有n次操作,每次操作只有成功与失败之分,成功对应1 ...

  6. bzoj4318 OSU!和bzoj 3450 Tyvj1952 Easy

    这俩题太像了 bzoj 3450 Tyvj1952 Easy Description 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:( 我们来简化一下这个游戏的规则 有n次点 ...

  7. bzoj-4318 OSU! 【数学期望】

    Description osu 是一款群众喜闻乐见的休闲软件.  我们可以把osu的规则简化与改编成以下的样子:  一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1 ...

  8. bzoj4318 OSU!

    传送门 题目 osu 是一款群众喜闻乐见的休闲软件.  我们可以把osu的规则简化与改编成以下的样子:  一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1个长度为n ...

  9. 【bzoj4318】【OSU!】期望dp——维护多个期望值递推

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62369739 Description osu 是 ...

随机推荐

  1. childNodes属性 和 nodeType属性

    childNodes属性可以用来获取任何一个元素的所有子元素,它是一个包含这个元素的全部子元素的数组:element.childNodes 如果需要把某个文档的body元素的全体子元素检索出来.首先使 ...

  2. 研究表明,VR社交有助于内向者改变性格

    目前,外界对于VR的普遍观点是这种头显提供了一种孤立的.反社会性的体验.但很少有人会意识到,虚拟现实同时也存在着能够增进人与人之间的关系的可能性. Facebook(脸书)IQ是人们连接这一社交网络的 ...

  3. mysql5.7.17安装问题

    在根目录新建data文件夹和my.ini,把ini复制到bin目录下才可以

  4. CodeForces 711B Chris and Magic Square

    简单题. 找一个不存在$0$的行,计算这行的和(记为$sum$),然后就可以知道$0$那个位置应该填的数字(记为$x$). 如果$x<=0$,那么无解,否则再去判断每一行,每一列以及两个斜对角的 ...

  5. DB2导入导出 学习笔记

    db2pd -osinfodb2mtrk -i -d (for aix)db2 get dbm cfg show detaildb2 get db cfg show detaildb2 get sna ...

  6. python中判断语句用两个or连接的奇葩

    学python的时候犯的一个错误,放在这吧.就是在循环某个列表的时候不要去操作它,这是容易忽略的一个地方.所以如果要操作某个列表本身,那么先把该列表copy一份,然后再读取的时候读copy的那份.操作 ...

  7. PAT乙级1034. 有理数四则运算(20)

    本题要求编写程序,计算2个有理数的和.差.积.商. 输入格式: 输入在一行中按照“a1/b1 a2/b2”的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前,分 ...

  8. 为什么Intent传递对象的时候必须要将对象序列化呢?

    Intent可以算是四大组件之间的胶水,比如在Activity1与Activity2之间传递对象的时候,必须要将对象序列化, 可是为什么要将对象序列化呢? Intent在启动其他组件时,会离开当前应用 ...

  9. Dynamic Programming - leetcode [动态规划]

    115. Distinct Subsequences 96. Unique Binary Search Trees 120. Triangle 123. Best Time to Buy and Se ...

  10. c# 索引器方法

    索引器方法允许我们构建能够以类似访问数组的语法来访问内部子类型的自定义类型 在语法上索引器方法和属性的定义很类似,一样是使用get,set,不同的是索引器是使用this[]创建的. 一个简单的索引器代 ...