HDU - 5894 Pocky(概率)

HDU5894 Pocky问题解析
本文解析了HDU5894—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就随机从其中一个点处剪成两端,左边的丢掉,右边的留下。继续上述过程,求最终剪木棒次数的期望值。
思路:
  1. 队友在最终推公式无果后转战找规律,最后还是是给找出来了,找规律的过程是ln2 = 0.693147。相继尝试多次比例关系后,发现ln(L/d)正好是答案-1,于是就有答案了,提交后AC。赛后搜了一下博客,发现还有积分形式的解法。

  2. 首先得知道在x长的木棒上随机选一点的几率为1/x。设在x长的木棒上能剪得次数的函数为f(x)。则有方程然后解方程就可以得到最终的结果为然后敲代码就可以了。

 

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

代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 1e5;
 4 typedef long long ll;
 5 int main()
 6 {
 7     double l,d;
 8     int n;
 9     scanf("%d",&n);
10     for(int i = 0; i<n; i++)
11     {
12         scanf("%lf%lf",&l,&d);
13         if(l<=d)
14             printf("%.6f\n",0.0);
15         else
16             printf("%.6f\n",log(l/d)+1);
17     }
18     return 0;
19 }
View Code

 

转载于:https://www.cnblogs.com/sykline/p/9741766.html

内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问题中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值