HDU 5984 题解 数学推导 期望
While the length of remaining pocky is longer than d, we perform
the following procedure. We break the pocky at any point on it in an
equal possibility and this will divide the remaining pocky into two
parts. Take the left part and eat it. When it is not longer than d, we
do not repeat this procedure.
Now we want to know the expected number of times we should repeat
the procedure above. Round it to 6 decimal places behind the decimal
point.
number of test cases. Each of the N lines contains two float-numbers L
and d respectively with at most 5 decimal places behind the decimal
point where 1 ≤ d, L ≤ 150.
OutputFor each test case, output the expected number of times rounded to 6 decimal places behind the decimal point in a line.Sample Input
6
1.0 1.0
2.0 1.0
4.0 1.0
8.0 1.0
16.0 1.0
7.00 3.00
Sample Output
0.000000
1.693147
2.386294
3.079442
3.772589
1.847298
分析:
题意:给定一个长度L的pocky,然后可以在任一点等概率地切割,切割后会把左边的部分吃掉,剩下右边的部分,
然后继续切割一直到剩下的长度小于d为止,问切割次数的期望值是?
假设切割当前长度为x的pocky时,期望值为f(x),如果x<=d,那么f(x)=0.
如果x>d,那么f(x)=1+f(1~d)+f(d~x),显然f(1~d)=0,即:f(x)=1+f(d~x)。
假设现在要切割d~x上的t点,切割t点的概率是1/x,切割该点的期望是f(t)/x,对t从d~x积分得f(d~x)=(1/x)*∫(d->x)f(t)dt.
那么f(x)=1+f(d~x)=1+(1/x)*∫(d->x)f(t)dt.
左右两边同时求导:f'(x)=(f(x)*x-∫(d->x)f(t)dt)/x^2①.又因为f(x)=1+(1/x)*∫(d->x)f(t)dt②.
联立①,②消去∫(d->x)f(t)dt得到f'(x)=1/x.即:f(x)=ln(x)+C,带入f(d)=0解得f(x)=ln(x/d)+1,根据题意得输入,x=L.
综上:
当L<=d时,输出0.000000.
否则,输出ln(L)-ln(d)+1.
AC code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
//freopen("input.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
double L,d;
scanf("%lf%lf",&L,&d);
if(L<=d) printf("%.6f\n",0.0);
else printf("%.6f\n",+log(L)-log(d));
}
return ;
}
END
HDU 5984 题解 数学推导 期望的更多相关文章
- ZOJ3329(数学推导+期望递推)
要点: 1.期望的套路,要求n以上的期望,则设dp[i]为i分距离终点的期望步数,则终点dp值为0,答案是dp[0]. 2.此题主要在于数学推导,一方面是要写出dp[i] = 什么,虽然一大串但是思维 ...
- HDU 5984(求木棒切割期望 数学)
题意是给定一长为 L 的木棒,每次任意切去一部分直到剩余部分的长度不超过 D,求切割次数的期望. 若木棒初始长度不超过 D,则期望是 0.000000: 设切割长度为 X 的木棒切割次数的期望是 F( ...
- HDU 5734 Acperience(数学推导)
Problem Description Deep neural networks (DNN) have shown significant improvements in several applic ...
- hdu.5211.Mutiple(数学推导 && 在logn的时间内求一个数的所有因子)
Mutiple Accepts: 476 Submissions: 1025 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 6553 ...
- HDU 5984 数学期望
对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...
- HDU 5073 Galaxy(Anshan 2014)(数学推导,贪婪)
Galaxy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total S ...
- HDU 5984.Pocky(2016 CCPC 青岛 C)
Pocky Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decora ...
- leetcode 343. Integer Break(dp或数学推导)
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- [国家集训队]整数的lqp拆分 数学推导 打表找规律
题解: 考场上靠打表找规律切的题,不过严谨的数学推导才是本题精妙所在:求:$\sum\prod_{i=1}^{m}F_{a{i}}$ 设 $f(i)$ 为 $N=i$ 时的答案,$F_{i}$ 为斐波 ...
随机推荐
- javascript基础学习第三天
☞ 命名法: 小驼峰命名法 和 大驼峰命名法(帕斯卡命名法) 变量命名规则:遵循小驼峰命名法 [变量名第一个字母小写后面每一个单词的首字母大写] var userNameAge; 函数命名规则:遵循帕 ...
- 微信小程序onLoad与onShow的区别
现在招聘网站上,会小程序开发都可以找到月薪不错的职位了,可见小程序认可度还是可以的! 小程序声明周期onLoad与onShow的区别? onLoad页面加载时调用,可以获取参数,通过options. ...
- CentOS7 部署K8S集群
虚拟机: VMware® Workstation 12 Pro 12.5.9 build-7535481操作系统:CentOS Linux release 7.6.1810 (Core) 部署 ...
- Linux命令(部分)
LINUX:实现某一功能,命令执行依赖于解释器程序. 内部:属于shell部分 外部:独立于shell解释器程序. 系统结构由外到内:用户 ⇢ 外围程序 ⇢ 硬件 ...
- ORM详解
讲解对象:ORM详解 作者:融水公子 rsgz 1 前言:开发流程正常只有简单的几步 0.1 配置数据库 0.2 定义模型 0.3 迁移文件 0.4 执行迁移生成数据表 0.5 使用模型类增删改查 2 ...
- angularjs通信以及postmessage与iframe通信
这篇文章是用markdown工具写的,有需要的可以使用vscode打开 # angularjs 控制器.组件之间的通信 ## 一.基于事件的方式 此方式下,主要通过 angularjs 内置指令` ...
- codeforces 355A Vasya and Digital Root
题意就是找出一个长度为k的整数,使得它的root为d,k的可能取值为1-1000. 第一眼看到这个题,无从下手,想到那么长的数,暴力肯定超时.其实不然,题目要求只要输出任何一个满足条件的即可,因为任何 ...
- python_0基础学习_day02
第二节 一,while while也称为无限循环.死循环 while 条件: 缩进 循环体 应用领域:音乐播放:单曲循环,列表循环,随机播放(也是有规律的) 登陆界面:…… 数学计算:1~100的和, ...
- maven打jar包包括依赖包
<build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId& ...
- 【Java例题】8.2 手工编写字符串统计的可视化程序
2. 手工编写字符串统计的可视化程序. 一个Frame窗体容器,布局为null,两个TextField组件,一个Button组件. Button组件上添加ActionEvent事件监听器Actio ...