bzoj4318: OSU!&&CF235BLet's Play Osu!
题目链接: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
Input
Output
Sample Input
0.5
0.5
0.5
Sample Output
HINT
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
2 seconds
256 megabytes
standard input
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.
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
其实和上一题一样,就是变成平方了而已。
#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!的更多相关文章
- [ACM_水题] ZOJ 3712 [Hard to Play 300 100 50 最大最小]
MightyHorse is playing a music game called osu!. After playing for several months, MightyHorse disco ...
- ZOJ3712:Hard to Play
MightyHorse is playing a music game called osu!. After playing for several months, MightyHorse disco ...
- 标准差分进化算法matlab程序实现(转载)
标准差分进化算法matlab程序实现 自适应差分演化算法方面的Matlab和C++代码及论文 差分进化算法 DE-Differential Evolution matlab练习程序(差异演化DE) [ ...
- ZCMU训练赛-H(模拟)
H - Hard to Play MightyHorse is playing a music game called osu!. After playing for several months ...
- 【BZOJ4318】OSU! 期望DP
[BZOJ4318]OSU! Description osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: 一共有n次操作,每次操作只有成功与失败之分,成功对应1 ...
- bzoj4318 OSU!和bzoj 3450 Tyvj1952 Easy
这俩题太像了 bzoj 3450 Tyvj1952 Easy Description 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:( 我们来简化一下这个游戏的规则 有n次点 ...
- bzoj-4318 OSU! 【数学期望】
Description osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: 一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1 ...
- bzoj4318 OSU!
传送门 题目 osu 是一款群众喜闻乐见的休闲软件. 我们可以把osu的规则简化与改编成以下的样子: 一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1个长度为n ...
- 【bzoj4318】【OSU!】期望dp——维护多个期望值递推
[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62369739 Description osu 是 ...
随机推荐
- VR电影这一新概念在中国电影道路上的探索
在12月的一个下午,Kevin Geiger正在进行关于VR中的故事讲述的一次再普通不过的演讲.地点是北京电影学院里一个围的水泄不通的场馆,他鼓励大家都来参与电影制作,无论是导演.演员还是电影行业的任 ...
- javascript 高级程序设计1--14章重点总结
js简介 首先介绍了js是一种专门与网页交互而设计的脚本语言.主要由ECMAScript 文档对象模型(DOM) 浏览器对象模型(BOM)三部分组成.分别用来提供核心语言,提供访问和操作网页内容的方法 ...
- C#中对属性和字段的理解
字段 C#中很少提到全局变量的概念, 引入了字段一词来代替全局变量, 但也并不是这样简单的, 字段会比全局变量的使用更难理解, 使用上会简单, 初学者当做成员变量或者全局变量不会有什么影响, 随着使用 ...
- MVC-工作原理
ASP.NET MVC的原理,其实就是使用HttpModule和HttpHandler将用户的请求拦截,按照设定的路由规则解释到相应的控制器和Action,加以执行.Module是一个比较宏观一点的概 ...
- CentOS 手动增加、删除swap区
SWAP是Linux中的虚拟内存,用于扩充物理内存不足而用来存储临时数据存在的.它类似于Windows中的虚拟内存.在Windows中,只可以使用文件来当作虚拟内存.而linux可以文件或者分区来当作 ...
- jdk 多版本安装 for mac
2016年mac上已经安装有jdk1.6的版本 目录在/Library/Java/JavaVirtualMachines/1.6.0.jdk 有时候mac版本跟新会自动删除jdk1.6 所以要去ma ...
- 前端必知的ajax
简介 异步交互 此篇只介绍部分方法,想了解更多就猛戳这里 1. load( url, [data], [callback] ) :载入远程 HTML 文件代码并插入至 DOM 中. url (Stri ...
- PHP静态延迟绑定简单示例
没怎么用过这个新特性,其实也不算新啦,试试吧,现在静态类的继承很方便了 <?php class A { protected static $def = '123456'; public stat ...
- 【Python】协程实现生产者消费者模型
协程的实现为协作式而非抢占式的,这是和进程线程的最大区别.在Python中,利用yield和send可以很容易实现协程. 首先复习下生成器. 如果一个函数使用了yield语句,那么它就是一个生成器函数 ...
- 手工杀毒辅助软件(PC Hunter) V1.51 免费绿色版
软件名称: 手工杀毒辅助软件(PC Hunter) 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win 32位/64位 软件大小: 4.7MB 图片预览: 软件简介: PC Hunter是 ...