HDU - 5984 Pocky【期望+积分】

Time limit 1000 ms
Memory limit 65536 kB

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.

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.


题目分析

本来还以为只是个普通期望。。没想到这么难。。也可能是我太菜了+_+

f ( x ) f(x) f(x)为长度为 x x x的期望次数
x ≤ d x\leq d xd,则 f ( x ) = 0 f(x)=0 f(x)=0

x ≥ d x\geq d xd,则
f ( x ) = 1 + 1 x (   ∫ 0 d f ( t ) d t   +   ∫ d x f ( t ) d t   ) f(x)=1+\frac{1}{x}(\ \int_0^df(t)dt\ +\ \int_d^xf(t)dt\ ) f(x)=1+x1( 0df(t)dt + dxf(t)dt )
f ( x ) = 1 + 1 x ∫ d x f ( t ) d t f(x)=1+\frac{1}{x}\int_d^xf(t)dt f(x)=1+x1dxf(t)dt

根据牛顿-莱布尼茨公式,设 F ′ ( x ) = f ( x ) F^{'}(x)=f(x) F(x)=f(x)

f ( x ) = 1 + 1 x ( F ( x ) − F ( d ) ) f(x)=1+\frac{1}{x}(F(x)-F(d)) f(x)=1+x1(F(x)F(d))

此时对 f ( x ) f(x) f(x)求导

f ′ ( x ) = x F ′ ( x ) − F ( x ) + F ( d ) x 2 f^{'}(x)=\frac{xF^{'}(x)-F(x)+F(d)}{x^2} f(x)=x2xF(x)F(x)+F(d)
f ′ ( x ) = x f ( x ) − ∫ d x f ( t ) d t x 2 f^{'}(x)=\frac{xf(x)-\int_d^xf(t)dt}{x^2} f(x)=x2xf(x)dxf(t)dt
f ′ ( x ) = x f ( x ) − x ( f ( x ) − 1 ) x 2 = 1 x f^{'}(x)=\frac{xf(x)-x(f(x)-1)}{x^2}=\frac{1}{x} f(x)=x2xf(x)x(f(x)1)=x1

f ( x ) = ln ⁡ x + C f(x)=\ln x+C f(x)=lnx+C
同时取右极限时
f ( d ) = ln ⁡ d + C = 1 ⇒ C = 1 − ln ⁡ d f(d)=\ln d+C=1\Rightarrow C=1-\ln d f(d)=lnd+C=1C=1lnd

代入上式
f ( x ) = ln ⁡ x d + 1 f(x)=\ln \frac{x}{d}+1 f(x)=lndx+1

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long lt;
typedef double dd;
 
int read()
{
    int f=1,x=0;
    char ss=getchar();
    while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
    while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
    return f*x;
}
 
int main()
{
    int T=read();
    while(T--)
    {
        dd L,d;
        scanf("%lf%lf",&L,&d);
        if(L<=d) printf("0.000000\n");
        else printf("%.6lf\n",log(L/d)+1.0);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值