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. Spring AOP 面向切面的Spring

    定义AOP术语 描述切面的常用术语有: 通知 (advice) 切点 (pointcut) 连接点 (joinpoint) 下图展示了这些概念是如何关联的 Spring 对AOP的支持 Spring提 ...

  2. 【Java】点击 JButton 修改 Jlabel 的文字和字体颜色

    要求: 点击 JButton 后执行一个方法 m(比较耗时),点击时改变 JLabel 的字体和颜色,方法 m 运行结束后再次修改 JLabel 的字体和颜色. 刚开始点击,都是方法 m 运行结束后, ...

  3. Java编程思想之十七 容器深入研究

    17.1 完整的容器分类方法 17.2 填充容器 import java.util.*; class StringAddress { private String s; public StringAd ...

  4. 夯实Java基础(二)——面向对象之封装

    1.封装介绍 封装封装,见名知意,就是把东西包装隐藏起来,不被外界所看见, 而Java特性封装:是指利用抽象数据类型将数据和基于数据的操作封装在一起,使其构成一个不可分割的独立实体,数据被保护在抽象数 ...

  5. kube-scheduler源码分析

    kubernetes集群三步安装 kube-scheduler源码分析 关于源码编译 我嫌弃官方提供的编译脚本太麻烦,所以用了更简单粗暴的方式编译k8s代码,当然官方脚本在编译所有项目或者夸平台编译以 ...

  6. CSS3 Flex 布局教程

    网页布局(layout)是 CSS 的一个重点应用. 布局的传统解决方案,基于盒状模型,依赖 display 属性 + position属性 + float属性.它对于那些特殊布局非常不方便,比如,垂 ...

  7. 【Kubernetes 系列一】Kubernetes 概述

    以下内容还可以通过 Google Slide 查看:https://docs.google.com/presentation/d/1eYP4bkVBojI_e6PqdpxIf0hvWO-JwAf-fy ...

  8. 使用windows powershell ISE管理命令窗口,并集成git命令

    写于2018-09-03(基于win10) 开启 win + s 输入 ise 操作 主要使用新建的power shell选项卡 将git集成到power shell中 安装准备 确定你的power ...

  9. Linux启动之旅

    引言 某出租房内,某台电脑的电源键被按下,于是开启了一段Linux启动之旅... BIOS 系统启动,首先进入BIOS. ● BIOS 为 Base Input/Output System(基本输入输 ...

  10. 带你剖析WebGis的世界奥秘----点和线的世界

    前言 昨天写了好久的博文我没保存,今天在来想继续写居然没了,气死人啊这种情况你们见到过没,所以今天重新写,我还是切换到了HTML格式的书写上.废话不多说了,我们现在就进入主题,上周我仔细研究了WebG ...