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


最新文章

  1. Live2d-cocos2dx教程(一)例子搭建及运行
  2. java spring hibernate
  3. 定时关闭AWS上的EC2机器实例
  4. Hive_进阶
  5. jQuery 的原型关系图,整体把握jQuery
  6. html5 上传图片.net实现
  7. JS App
  8. ubuntu 14.04 下 安装samba 及SSH 服务端的方法
  9. Design Pattern —— Prototype /Template Method/Iterator/Composite/Bridge
  10. Android自己定义控件——3D画廊和图像矩阵
  11. C#多线程的用法4-线程间的协作lock快捷方式
  12. Python3 ——斐波那契数列(经典)
  13. hibernate坑边闲话
  14. 洛谷P2150 寿司晚宴
  15. Alienware 15 R3 装Ubuntu 和 win10 双系统
  16. 洛谷.2042.[NOI2005]维护数列(Splay)
  17. scala-高阶函数
  18. VxWorks笔记
  19. 数的划分(NOIP2001&水题测试2017082401)
  20. Python 自定义异常处理Error函数

热门文章

  1. javascript基础学习第三天
  2. Netty 客户端使用指数退避机制实现重连
  3. springcloud-熔断监控Hystrix Dashboard和Turbine
  4. Waiting for 1 instance(s) to be deallocated
  5. vuex快速入门
  6. springboot+kafka+邮件发送(最佳实践)
  7. 一文搞懂 Prometheus 的直方图
  8. luogu1330_封锁阳光大学 图的遍历
  9. 学习TensorFlow的第一天
  10. 数据结构之堆栈C++版