HDU - 5894 Pocky(概率)
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就随机从其中一个点处剪成两端,左边的丢掉,右边的留下。继续上述过程,求最终剪木棒次数的期望值。
思路:
- 队友在最终推公式无果后转战找规律,最后还是是给找出来了,找规律的过程是ln2 = 0.693147。相继尝试多次比例关系后,发现ln(L/d)正好是答案-1,于是就有答案了,提交后AC。赛后搜了一下博客,发现还有积分形式的解法。
- 首先得知道在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(概率)的更多相关文章
- hdu 5894 hannnnah_j’s Biological Test 组合数学
传送门:hdu 5894 hannnnah_j’s Biological Test 题目大意:n个座位,m个学生,使每个学生的间隔至少为k个座位 组合中的插空法 思路:每个学生先去掉k个空位间隔,剩下 ...
- 排列组合+组合数取模 HDU 5894
// 排列组合+组合数取模 HDU 5894 // 题意:n个座位不同,m个人去坐(人是一样的),每个人之间至少相隔k个座位问方案数 // 思路: // 定好m个人 相邻人之间k个座位 剩下就剩n-( ...
- HDU 5894 hannnnah_j’s Biological Test【组合数学】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5894 题意: 一个圆桌上有$n$个不同的位置,$m$个相同的人安排到这$n$个位置上,要求两人相邻的 ...
- HDU 5984.Pocky(2016 CCPC 青岛 C)
Pocky Let’s talking about something of eating a pocky. Here is a Decorer Pocky, with colorful decora ...
- HDU 4050 wolf5x 概率dp 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=4050 题意: 现在主角站在0处,需要到达大于n的位置 主角要进入的格子有三种状态: 0. 不能进入 1. 能进入 ...
- HDU 4089 Activation 概率DP 难度:3
http://acm.hdu.edu.cn/showproblem.php?pid=4089 这道题中一共有两个循环: 1.事件1 如果一直落在Activation failed事件上,那么就会重新继 ...
- HDU 4035 Maze 概率dp,树形dp 难度:2
http://acm.hdu.edu.cn/showproblem.php?pid=4035 求步数期望,设E[i]为在编号为i的节点时还需要走的步数,father为dfs树中该节点的父节点,son为 ...
- HDU 4035Maze(概率DP)
HDU 4035 Maze 体会到了状态转移,化简方程的重要性 题解转自http://blog.csdn.net/morgan_xww/article/details/6776947 /** dp ...
- HDU 3853LOOPS(简单概率DP)
HDU 3853 LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...
随机推荐
- 我所不知的 javascript Object 的一些现象
1.我们都知道对象访问属性有两种方法,一种是使用 . 操作符,使用它添加的属性名必须满足标识符的命名规范:另一种是使用 [] 键访问的方法,可以接受任意UTF-8/Unicode字符串作为属性名,在E ...
- java.lang.NoClassDefFoundError: org/apache/commons/lang/xwork/StringUtils
java.lang.NoClassDefFoundError: org/apache/commons/lang/xwork/StringUtils Struts2框架下使用JSON插件时.程序保存找不 ...
- java多线程——线程通信
一.线程通信目标 1.线程通信的目标是使线程间能够互相发送信号 2.线程通信使线程能够等待其他线程的信号 二.几种方式 1.通过共享对象 2.忙等待 线程 B 运行在一个循环里,以等待信号 (不释放c ...
- 洛谷 P2055 [ ZJOI 2009 ] 假期的宿舍 —— 二分图匹配
题目:https://www.luogu.org/problemnew/show/P2055 二分图匹配: 注意要连边的话对方必须有床! 代码如下: #include<iostream> ...
- JSP-Runoob:JSP 异常处理
ylbtech-JSP-Runoob:JSP 异常处理 1.返回顶部 1. JSP 异常处理 当编写JSP程序的时候,程序员可能会遗漏一些BUG,这些BUG可能会出现在程序的任何地方.JSP代码中通常 ...
- openstack instance resize to
Icehouse resize No valid host was found Hi all!! We're currently experimenting an error that's it's ...
- IP V4 和 IP V6 初识
IP V4 是互联网协议的第四版 地址长度为32位,4字节,用十进制表示 格式为:A.B.C.D 最大的问题在于网络地址资源有限,严重制约了互联网的应用和发展 IP V6 是互联网协议的I ...
- 数据库得到too many connections”错误信息
查进程 show processlist删除进程 kill ID查完整sql show full processlist; 连数据库 MySQL -S /tmp/mysql.sock 或 ...
- nginx入门学习
1.yum解决编译nginx所需的依赖包,之后你的nginx就不会报错了 yum install gcc patch libffi-devel python-devel zlib-devel bzip ...
- js基础---object对象
//**********************************复杂JSON举例**************************************** var Jsondata={d ...