HDU5894—Pocky

Problem Description:

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.

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 题意:有一个木棒,如果它的长度L大于d就随机从其中一个点处剪成两端,左边的丢掉,右边的留下。继续上述过程,求最终剪木棒次数的期望值。
思路:
  1. 队友在最终推公式无果后转战找规律,最后还是是给找出来了,找规律的过程是ln2 = 0.693147。相继尝试多次比例关系后,发现ln(L/d)正好是答案-1,于是就有答案了,提交后AC。赛后搜了一下博客,发现还有积分形式的解法。
  2. 首先得知道在x长的木棒上随机选一点的几率为1/x。设在x长的木棒上能剪得次数的函数为f(x)。则有方程然后解方程就可以得到最终的结果为然后敲代码就可以了。

PS:感谢:解惑博客(博主真的很强啊)

代码:

 #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
typedef long long ll;
int main()
{
double l,d;
int n;
scanf("%d",&n);
for(int i = ; i<n; i++)
{
scanf("%lf%lf",&l,&d);
if(l<=d)
printf("%.6f\n",0.0);
else
printf("%.6f\n",log(l/d)+);
}
return ;
}

HDU - 5894 Pocky(概率)的更多相关文章

  1. hdu 5894 hannnnah_j’s Biological Test 组合数学

    传送门:hdu 5894 hannnnah_j’s Biological Test 题目大意:n个座位,m个学生,使每个学生的间隔至少为k个座位 组合中的插空法 思路:每个学生先去掉k个空位间隔,剩下 ...

  2. 排列组合+组合数取模 HDU 5894

    // 排列组合+组合数取模 HDU 5894 // 题意:n个座位不同,m个人去坐(人是一样的),每个人之间至少相隔k个座位问方案数 // 思路: // 定好m个人 相邻人之间k个座位 剩下就剩n-( ...

  3. HDU 5894 hannnnah_j’s Biological Test【组合数学】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5894 题意: 一个圆桌上有$n$个不同的位置,$m$个相同的人安排到这$n$个位置上,要求两人相邻的 ...

  4. HDU 5984.Pocky(2016 CCPC 青岛 C)

    Pocky Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decora ...

  5. HDU 4050 wolf5x 概率dp 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=4050 题意: 现在主角站在0处,需要到达大于n的位置 主角要进入的格子有三种状态: 0. 不能进入 1. 能进入 ...

  6. HDU 4089 Activation 概率DP 难度:3

    http://acm.hdu.edu.cn/showproblem.php?pid=4089 这道题中一共有两个循环: 1.事件1 如果一直落在Activation failed事件上,那么就会重新继 ...

  7. HDU 4035 Maze 概率dp,树形dp 难度:2

    http://acm.hdu.edu.cn/showproblem.php?pid=4035 求步数期望,设E[i]为在编号为i的节点时还需要走的步数,father为dfs树中该节点的父节点,son为 ...

  8. HDU 4035Maze(概率DP)

    HDU 4035   Maze 体会到了状态转移,化简方程的重要性 题解转自http://blog.csdn.net/morgan_xww/article/details/6776947 /** dp ...

  9. HDU 3853LOOPS(简单概率DP)

    HDU 3853    LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...

随机推荐

  1. Project Euler:Problem 42 Coded triangle numbers

    The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...

  2. Redis 持久化,写入磁盘的方式

    如果帮到了您,可以支持一下,谢谢您的支持! Redis是一个支持持久化的内存数据库=>也就是说redis需要经常将内存中的数据同步到磁盘来保证持久化. redis支持四种持久化方式, 一是 Sn ...

  3. POJ2393 Yogurt factory 【贪心】

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6821   Accepted: 3488 De ...

  4. Script Library 配置 和 使用

    Script Library有两个级别,Workspace级别和Project级别 使用:这里的package指的是Script Library下的文件夹名,和引用代码里的package没有关系

  5. 【Codevs1288】埃及分数

    Position: http://codevs.cn/problem/1288/ Description 在古埃及,人们使用单位分数的和(形如1/a的, a是自然数)表示一切有理数. 如:2/3=1/ ...

  6. HDU3487 Play with Chain splay 区间反转

    HDU3487 splay最核心的功能是将平衡树中的节点旋转到他的某个祖先的位置,并且维持平衡树的性质不变. 两个操作(数组实现) cut l,r, c把[l,r]剪下来放到剩下序列中第c个后面的位置 ...

  7. Hadoop 的使用

    hadoop:hadoop启动:./sbin/start-dfs.shhadoop关闭:./sbin/stop-dfs.shbin文件用于在HDFS创建数据HDFS 中创建用户目录:./bin/hdf ...

  8. SEL是啥玩意

    一.了解SEL前的准备-----isa指针简述 1.一个类就像一个 C 结构,NSObject 声明了一个成员变量: isa.由于 NSObject 是所有类的根类,所以所有的对象都会有一个 isa ...

  9. PCB MS SQL 标量函数(CLR) 实现DataTable转HTML的方法

    一.准备需转为HMLT字符串的DataTable数据 在数据库中执行一段SQL返回的数据 需转换后的HTML的文本 <html ><head></head>< ...

  10. html5做的一个激光条

    <!DOCTYPE HTML><html lang="zh-cn"><head> <title>CSS3激光加载条</titl ...