Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decorative stripes in the coating, of length L.
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.

InputThe first line of input contains an integer N which is the
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 题解 数学推导 期望的更多相关文章

  1. ZOJ3329(数学推导+期望递推)

    要点: 1.期望的套路,要求n以上的期望,则设dp[i]为i分距离终点的期望步数,则终点dp值为0,答案是dp[0]. 2.此题主要在于数学推导,一方面是要写出dp[i] = 什么,虽然一大串但是思维 ...

  2. HDU 5984(求木棒切割期望 数学)

    题意是给定一长为 L 的木棒,每次任意切去一部分直到剩余部分的长度不超过 D,求切割次数的期望. 若木棒初始长度不超过 D,则期望是 0.000000: 设切割长度为 X 的木棒切割次数的期望是 F( ...

  3. HDU 5734 Acperience(数学推导)

    Problem Description Deep neural networks (DNN) have shown significant improvements in several applic ...

  4. hdu.5211.Mutiple(数学推导 && 在logn的时间内求一个数的所有因子)

    Mutiple  Accepts: 476  Submissions: 1025  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 6553 ...

  5. HDU 5984 数学期望

    对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...

  6. HDU 5073 Galaxy(Anshan 2014)(数学推导,贪婪)

    Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total S ...

  7. HDU 5984.Pocky(2016 CCPC 青岛 C)

    Pocky Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decora ...

  8. leetcode 343. Integer Break(dp或数学推导)

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  9. [国家集训队]整数的lqp拆分 数学推导 打表找规律

    题解: 考场上靠打表找规律切的题,不过严谨的数学推导才是本题精妙所在:求:$\sum\prod_{i=1}^{m}F_{a{i}}$ 设 $f(i)$ 为 $N=i$ 时的答案,$F_{i}$ 为斐波 ...

随机推荐

  1. context创建过程解析(二)之deployWARs

    HostConfig.deployApps() //在监听到start事件类型,也就是StandardHost调用startInternal protected void deployApps() { ...

  2. 8 NLP-自然语言处理Demo

    1 NLP(自然语言处理) 1.1相似度 相似度和距离之间关系: 1.文本相似度: 1) 语义相似.但字面不相似: 老王的个人简介 铁王人物介绍 2) 字面相似.但是语义不相似: 我吃饱饭了 我吃不饱 ...

  3. Core CLR 自定义的Host官方推荐的一种形式(第一种)

    .Net Core CLR提供两种Host API访问 托管代码的形式,按照微软官方的说法,一种是通过CoreClr.DLL来直接调用托管生成的DLL程序集,另外一种是通过CoreClr里面的C导出函 ...

  4. 小白学python-day08-文件及其操作、字符串字典类型转换

    今天是day08,以下是学习总结: 但行努力,莫问前程. ----------------------------------------------------------------------- ...

  5. 注解与AOP切面编程实现redis缓存与数据库查询的解耦

    一般缓存与数据库的配合使用是这样的. 1.查询缓存中是否有数据. 2.缓存中无数据,查询数据库. 3.把数据库数据插入到缓存中. 其实我们发现 1,3 都是固定的套路,只有2 是真正的业务代码.我们可 ...

  6. 大型系列课程之-七夕告白之旅vbs篇

    也许,世间所有的美好的东西,都是需要仪式感的,遇到了一年一度的七夕节,怎么过这个节日,成了很多心中有爱的人关注的事情,七夕不浪漫,人间不值得,七夕,发源于中国,这个美好的节日,来自动人的神话故事传说牛 ...

  7. MyBatis 核心配置综述之 ResultSetHandler

    目录 ResultSetHandler 简介 ResultSetHandler 创建 ResultSetHandler 处理结果映射 DefaultResultSetHandler 源码解析 我们之前 ...

  8. 0x15 字符串

    KMP算法 next数组的求法 void calc_next() { next[]=; , j=; i<=n; ++i) { &&a[i]!=a[j+]) j=next[j]; ...

  9. Css3动画效果,彩色文字效果,超简单的loveHeart

    <!DOCTYPE html><html><head><meta charset="utf-8" /><title>Cs ...

  10. 转载 | Sublime Text3 安装以及初次配置

    本文引自:http://blog.csdn.net/u011272513/article/details/52088800 工具:官网下载:Sublime Text3 安装:直接运行安装.http:/ ...