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短信备份及插入笔记
实现备份短信到xml文件和像短信中插入一条数据 一.实现短信将备份到xml文件中 在布局文件中定义一个按钮,定义点击事件为copyClick MainActivity.java: package co ...
- rest framework 分页,版本
分页 分页器的引入 from rest_framework.pagination import PageNumberPagination, LimitOffsetPagination, CursorP ...
- mongoDB 小练习
1 创建数据库名为 grade > use grade switched to db grade 2 创建集合 class 3 插入若干数据 格式如下{name:xxx,age:xxx,sex: ...
- 【BZOJ5492】[HNOI2019]校园旅行(bfs)
[HNOI2019]校园旅行(bfs) 题面 洛谷 题解 首先考虑暴力做法怎么做. 把所有可行的二元组全部丢进队列里,每次两个点分别向两侧拓展一个同色点,然后更新可行的情况. 这样子的复杂度是\(O( ...
- 【BZOJ5495】[十二省联考2019]异或粽子(主席树,贪心)
[BZOJ5495][十二省联考2019]异或粽子(主席树,贪心) 题面 BZOJ 洛谷 题解 这不是送分题吗... 转异或前缀和,构建可持久化\(Trie\). 然后拿一个堆维护每次的最大值,每次如 ...
- logstash/conf.d文件编写
logstash-01.conf input { beats { port => 5044 host => "0.0.0.0" type => "log ...
- [curl]convert curl to python Ruby
https://curl.trillworks.com/
- 用expect实现SCP/SSH自动输入密码登录
在命令行ssh远程登录服务器和scp远程传输文件都需要交互式输入密码,无法像mysql登录数据库 mysql -uroot -p123456一样直接完成. 其实可以用脚本依赖expect来达到这一目的 ...
- Springboot 4.Springboot 集成SwaggerUi
SwaggerUi就是自动生成接口文档的这么一个类似于插件的工具,可以直接访问接口. 首先打开pom文件,将插件引进来,然后增加一个属性<properties>,用来设置版本号的,然后直接 ...
- redis-sentinel高可用配置(2)
一:说明 前面我们已经配置了redis的主从配置(链接),这种主从架构有一个问题,当主master出现了故障了,怎么切换到从服务器上呢? 第一种:手动切换, 这种肯定会造成比较长一段时间的用户不能访问 ...