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 ...
随机推荐
- Vivado2016旧工程IP移动到新工程
前言 在VIVADO中图形化界面生成IP,在旧工程中使用后,如果想在新的工程中使用这个IP但又不想再次生成一次,则就需要把就旧工程中的IP导入到新工程中. 流程 1.旧工程IP生成的目录如下,IP为C ...
- min_25筛
min_25筛 用来干啥? 考虑一个积性函数\(F(x)\),用来快速计算前缀和\[\sum_{i=1}^nF(i)\] 当然,这个积性函数要满足\(F(x),x\in Prime\)可以用多项式表示 ...
- Day046--JavaScript-- DOM操作, js中的面向对象, 定时
一. DOM的操作(创建,追加,删除) parentNode 获取父级标签 nextElementSibling 获取下一个兄弟节点 children 获取所有的子标签 <!DOCTYPEhtm ...
- C语言程序设计I—寒假作业安排
20188402http://www.cnblogs.com/1793979463hyx/
- 速查mysql数据大小
速查mysql数据大小 # 1.查看所有数据库大小 mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data ...
- Numpy系列(五)- 复制和视图
当计算和操作数组时,它们的数据有时被复制到新的数组中,有时不复制.这里我们做个区分. 完全不复制 简单赋值不会创建数组对象或其数据的拷贝. import numpy as np a = np.aran ...
- [物理学与PDEs]第2章习题12 严格凸性的转换
设 $L=L(\xi_0,\xi_1,\cdots,\xi_n)$ 关于变量 $\xi_0>0,\xi_1,\cdots,\xi_n$ 为严格凸的. 证明函数 $$\bex M=\cfrac{1 ...
- [物理学与PDEs]第2章习题4 习题 3 的变分
设 ${\bf u}$ 为满足第 3 题中条件的解. 证明 ${\bf u}$ 为如下变分问题 $$\bex \min_{{\bf w}\in A}\cfrac{1}{2}\int_\Omega |{ ...
- 面试经验合集-Java后端<一>
面试一:CDKHXJSYJS 时间:2018-12-29 周六 地点:航天科技大厦32楼 一 技术题目 <回忆版> 1.上下转型 2.Java异常:分类.处理.设计 3.二叉排序树 ...
- JavaSE笔记-注释
Annotation Annotation是一个接口,可以把Annotation当成一个修饰符 Annotation的定义 注解通过@interface定义 public @interface Tes ...