2016青岛区域赛c题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5984

题意:有一个长度为l的面包,等概率地从中选取一个点,吃掉左边部分,然后再选再吃。直到剩下的部分小于等于d就停止,问吃的次数的期望。

思路:用 f(x)表示绳长为 x 时切割次数的期望,当x<=d时,f(x)=0;当x>d时,根据概率论推导可知,f(x)=1+lnx-lnd;

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
typedef long long LL;
using namespace std;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        double l,d;
        scanf("%lf%lf",&l,&d);
        if(l<=d)
            printf("0.000000\n");
        else
            printf("%.6lf\n",1+log(l/d));
    }
    return 0;
}

       

猜你喜欢

转载自www.cnblogs.com/zcb123456789/p/12264350.html