#P1597. Pocky

Pocky

Description

题目来源->2016年青岛icpc区域赛C题

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.

题目大意:

让我们吃些巧克力棒。这根巧克力棒长度为L。 当剩余巧克力棒的长度大于d时,我们执行以下步骤。掰开巧克力棒。在相等的概率下掰成两部分,吃掉它的左边。(断开的点随机,每个点是断点的概率相同)

当它不大于d长,我们不重复此过程。 现在我们想知道预期我们应该重复上述过程的次数,将其四舍五入到小数点后6位。

Input Format

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.

输入的第一行包含一个整数N,它是测试用例的数量。N行中的每行包含两个浮点数L和d,1≤d,L≤150。

Output Format

For each test case, output the expected number of times rounded to 6 decimal places behind the decimal point in a line.

对于每个测试用例,输出期望的次数,四舍五入到一行中小数点后6个小数位。

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​
0.000000
1.693147
2.386294
3.079442
3.772589
1.847298​

Hint

随机化的计算可能会用到数学期望

Source

数学期望 数论