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. leetCode 54.Spiral Matrix(螺旋矩阵) 解题思路和方法

    Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matri ...

  2. 一个尖括号能干什么,画一个笑脸开始(为了支持交互,它又增添了JavaScript。HTML页面也越来越臃肿。于是CSS便诞生了。API和核心代码的出现使HTML能够访问更复杂的软件功能--支持更高级的交互和云服务集成。这就是今天的HTML5)

    一个尖括号 < 一个尖括号能干什么 < ? 你可以编出一顶帽子 <(:-p 或一张笑脸 :-> 再或者更直接一些 20世纪90年代初,html作为一种简单标记语言面世,用于在互 ...

  3. Android-通过SlidingPaneLayout高仿微信6.2最新版手势滑动返回(一)

    近期更新了微信版本号到6.2.发现里面有个很好的体验,就是在第二个页面Activity能手势向右滑动返回,在手势滑动的过程中能看到第一个页面,这样的体验很赞,这里高仿了一下. 这里使用的是v4包里面的 ...

  4. iOS-获取子视图父控制器

    开发中有的时候需要涉及当前视图的父级视图,可以通过UIResponder来获取,有两种实现方式: UIView *next=sender; while ([next superview]) { nex ...

  5. 分类(category)是门学问

    分类的精细程度表现了人类的文明程度. 1. 学科分类 cybernetics:控制论:

  6. 绑定树tree 的后台方法

    #region 获取部门列表树集合         /// <summary>         /// 获取部门列表树集合         /// </summary>     ...

  7. ZOJ 3666 博弈 SG函数

    SG函数: 对于任意状态,定义SG(x)=mex(S),其中S是x的后继状态的SG函数值集合,mex(S)表示不再S内的最小非负整数 SG(X)=0当且仅当x为必败态. 解: 构造一个有向无环图(树) ...

  8. scrapy 框架持久化存储

    1.基于终端的持久化存储 保证爬虫文件的parse方法中有可迭代类型对象(通常为列表或字典)的返回,该返回值可以通过终端指令的形式写入指定格式的文件中进行持久化操作. # 执行输出指定格式进行存储:将 ...

  9. Java保存错误日志信息

    我们平时在撸代码的时候,有时候需要将某个代码块的具体错误信息保存到数据库或文件中,以便日后方便快速的查找问题. 使用e.printStackTrace(),我们可以将信息保存在具体的变量中,然后写入数 ...

  10. day03_12/13/2016_bean属性的设置之setter方法注入