HDU 5984.Pocky(2016 CCPC 青岛 C)
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.
Input
The 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.
Output
For 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
设f(x)为长度为x的木棒的期望。
(1)当x<=d时,已经不用分割了,故期望f(x)=0;
(2)当x>d时,f(x)=1+f(0~d)+f(d~x);
①1:表示在长度为x的木棒上分割一次
②f(0~d):分割点在0~d上的期望,由(1)f(0~d)=0
③f(d~x):分割点在d~x上的期望,关键就是求f(d~x)
f(d~x)的求解:在某个点上分割的概率是1/x,则在t处分割的期望:(1/x)*f(t),那么在d~x上将该式积分起来就是f(d~x);
大佬博客:https://www.oyohyee.com/post/HDU/5984/代码:
#include <cstdio>
#include <cmath> using namespace std; int main()
{
int t;
scanf("%d", &t);
while(t--)
{
double a, b;
scanf("%lf %lf", &a, &b);
if(a<=b) printf("0.000000\n");
else
{
double ans = log(a) - log(b) + 1.0;
printf("%.6f\n", ans);
}
}
return ;
}
HDU 5984.Pocky(2016 CCPC 青岛 C)的更多相关文章
- hdu 5881 Tea (2016 acm 青岛网络赛)
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5881 Tea Time Limit: 3000/1000 MS (Java/Others) Me ...
- HDU 5884 Sort -2016 ICPC 青岛赛区网络赛
题目链接 #include <iostream> #include <math.h> #include <stdio.h> #include<algorith ...
- HDU 5881 Tea -2016 ICPC 青岛赛区网络赛
题目链接 题意:有一壶水, 体积在 L和 R之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水的 ...
- HDU 5879 Cure -2016 ICPC 青岛赛区网络赛
题目链接 题意:给定一个数n,求1到n中的每一项的平方分之一的累加和. 题解:题目没有给数据范围,而实际上n很大很大超过long long.因为题目只要求输出五位小数,我们发现当数大到一定程度时值是固 ...
- HDU 5918 SequenceI (2016 CCPC长春站 KMP模版变形)
这个题目的数据应该是比较弱的,赛场上的时候我们暴力也过了,而且我的kmp居然比暴力还要慢-- 这个变形并不难,跳着选数,把漏掉的位置补上就可以了. 代码如下: #include<iostream ...
- HDU 5936 Difference ( 2016 CCPC 杭州 D && 折半枚举 )
题目链接 题意 : 给出一个 x 和 k 问有多少个 y 使得 x = f(y, k) - y .f(y, k) 为 y 中每个位的数的 k 次方之和.x ≥ 0 分析 : f(y, k) - y = ...
- HDU 5923 Prediction(2016 CCPC东北地区大学生程序设计竞赛 Problem B,并查集)
题目链接 2016 CCPC东北地区大学生程序设计竞赛 B题 题意 给定一个无向图和一棵树,树上的每个结点对应无向图中的一条边,现在给出$q$个询问, 每次选定树中的一个点集,然后真正被选上的是这 ...
- 2016 CCPC 东北地区重现赛
1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08 HDU5929 Basic Data Structure 模拟,双端队列 1.题意:模拟一个栈的操 ...
- HDU 5984 数学期望
对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...
随机推荐
- Android学习第十天
计算机表示图形的几种方式 a) Bmp:以高质量保存,用于计算机 b) Jpg:以良好的质量保存,用于计算机或网络 c) Png:以高质量保存 d) ...
- c# 获取端口的连接数,网站的连接数
端口连接数: public static int PortTcpConnection(int port) { IPGlobalProperties properti = IPGlobalPropert ...
- IDEA或Webstorm设置Terminal终端字体大小
File---Settings
- Linux测试硬盘读性能的常用工具-hdparm和dd俩搭档
Linux测试硬盘读性能的常用工具-hdparm和dd俩搭档 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.hparm # 它用来在基于 Linux的系统上获取或 ...
- 第三节: EF调用普通SQL语句的两类封装(ExecuteSqlCommand和SqlQuery )
一. 前言 在前面的两个章节中,我们分别详细介绍了EF的增删改的两种方式(方法和状态)和EF查询的两种方式( Lambda和Linq ),进行到这里,可以说对于EF,已经入门了,本来应该继续往下进行E ...
- JavaScript IIEF 模仿块级作用域
前言 JavaScript没有块级作用域的概念.但是通过IIEF 立即执行函数我们可以实现块级作用域. function outputNumbers(count){ for (var i=0; i & ...
- [物理学与PDEs]第3章第2节 磁流体力学方程组 2.2 考虑到电磁场的存在对流体力学方程组的修正
1. 连续性方程 $$\bex \cfrac{\p \rho}{\p t}+\Div(\rho{\bf u})=0. \eex$$ 2. 动量守恒方程 $$\bex \cfrac{\p }{\p ...
- eclipse+tomcat出现警告警告: [SetPropertiesRule]...
启动tomcat出现警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to ' ...
- 激活函数——tanh函数(理解)
0 - 定义 $tanh$是双曲函数中的一个,$tanh()$为双曲正切.在数学中,双曲正切“$tanh$”是由基本双曲函数双曲正弦和双曲余弦推导而来. $$tanhx=\frac{sinhx}{co ...
- url的三个js编码函数escape(),encodeURI(),encodeURIComponent()简介【转】
引子 浏览器URl地址,上网一定会用到,但是浏览器地址有中文或者浏览器url参数操作的时候,经常会用到encodeURIComponent()和decodeURIComponent()以及encode ...