Another Google question - drop glassballs from a building 1

探讨使用两个玻璃球寻找100层高楼中会使球碎裂的最低楼层的最优策略,通过数学方法找到最少尝试次数,并分析如何将此方法扩展至多个玻璃球。
Here is the question:

原题: 有一个100层高的大厦,你手中有两个相同的玻璃围棋子。从这个大厦的某一层扔下围棋子就会碎,用你手中的这两个玻璃围棋子,找出一个最优的策略,来得知那个临界层面。

I copied and pasted the above since I can't type Chinese most of the time. A google yield a few articles that I copied too:

为了得到两个棋子的最优策略,我们先简化问题,看看一个棋子的情况。如果手中只有一个棋子,为了得知临界层面,你只有一种选择:从2楼开始,一层地试,直到棋子被打碎,此时你站的楼层就是所求的临界层面。在最差的情况下,我们需要投掷99-2+1=98次,你可能奇怪为什么不是100-2+1=99次,那是因为题目已经告诉我们“从这个大厦的某一扔下就会碎”,所以在99扔下来还没碎的话就不用去100层了——从那里扔它一定会碎。

从一个棋子的策略我们可以看出,一个棋子就足以解答这个问题了。现在又多了一个棋子,该如何利用它呢?很自然地,我们希望能通过这个棋子缩小这种一查找的范围。为了缩小范围,我们将整个大厦数分成x段,在这x段中查找那个临界段,然后在临界段中再一地找临界。比如可以将大楼分成4段,我们分别在25、50、75投掷棋子,以确定临界段;如果临界段在25到50,我们再从26开始一查找临界

分析到这里,问题就转化成了如何确定分段数x使棋子投掷的次数最少的问题。在最差的情况下,要确定临界段,我们需要投掷
100/x-1次;确定了临界段之后要确定临界,我们需要再投掷x-1次。因此,问题就成了求函数f(x)=(100/x-1)+(x-1)的最小值问题。先对f(x)求导,f’(x)=1-100/x2,令f’(x)=0求出驻点x=10(x=-10舍去)。由于f(x)存在最小值且只有一个驻点,所以当x=10时f(x)取得最小值,最小值为18。这样就解答了这个问题。

上文贴出之后,我又在优快云和ChinaUnix的论坛看了一些网友的解法,发现上述方法并非最优。将大楼分段以缩小查找范围的想法是没错的,问题在于是否应该均匀分段。

题目要求我们总的投掷次数要最少。在分段之后,总的投掷次数就等于确定临近段的次数加上确定临界层的次数。如果我们均匀分段,则确定临界层的最坏投掷数是固定的(9次),随着我们确定临近段的投掷次数增加,总的投掷次数也在增加。这样一来,随着临界段的不同,投掷次数也不同。

这也就是为什么上述方法不是最优的原因:投掷次数分布不均。按最坏情况估计,这种方法就多做了几次。为了使最坏情况的投掷数最小,我们希望无论临界段在哪里,总的投掷数都不变,也就是说将投掷数均匀分布

接下来的解决方案就很容易想出了:既然第一步(确定临界段)的投掷数增加不可避免,我们就让第二步(确定临界层)的投掷数随着第一步的次数增加而减少。第一步的投掷数是一次一次增加的,那就让第二步
的投掷数一次一次减少。假设第一次投掷的层数是f,转化成数学模型,就是要求f+(f-1)+...+2+1>=99,即f(f+1)/2>=99,解出结果等于14。

这种方法要推广到n(n>2)个棋子的情况比较困难。我初步的想法是,先用均匀分段求出一个解,然后修正这个解使投掷次数均匀分布。如果你对此有兴趣,不妨思考一下具体的解法。

The key here is to obtain even distribution on how many times in the worst case we have to try regardless where the breaking floor is.

Let's look at the way how we get there, we start with the sequence

(1)        1, 2, 3, 4, 5, 6, 7, 8, 9, ... , 100      

Then we take the sum on all numbers before,

(2)        1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, ...   

The last number 105 > 100, and it's the 14th element in the array (2). Now if we start from the 14th element, which is 14, from the first series (1), if the glass ball breaks, then we need to try at most 13 times below 14th floor to find the breaking floor(start from 1 to 13).

If it's not broken at 14th, then we move up 13 floors(13 is the number before 14) to 27th and check there. If it breaks at 27th, then we know the breaking floor is between 14 and 27(exclude both ends). Since there are only 12 floors in between, totally it takes us 12 + 2 (1 for 14, 1 for 27) trials.

Eventually we will cover all 100 floors(in fact we can cover 105) because 100 < 105 = sum of 1 to 14. And for the first 14 floors, the next 13 floors, the next 12 floors, we all get 14 trials in the worst case.

The floors that we should go if previous trials won't break the glass ball are:

(A)        14, 14+13=27, 14+13+12=39, 14+13+12+11=50, ...

So the process is:
1. take the summations on series (1) to form a new series (2)
2. find the index 14 so that the element with this index, namely 105, is larger than 100.
3. use this index on the series (1) again to sum up backward, namely, series (A).

Once we understand this logic, actually it's easy to extend this method to n glass balls, namely, we just keep taking summations, use (2) as the base and take the summation, we now get

(3)      1, 4, 10, 20, 35, 56, 84, 120, ...

(4)      1, 5, 15, 35, 70, 105, ...

(5)      1, 6, 21, 66, 136, ....

(6)      1, 7, 28, 94, 230, ...

(7)      1, 8, 36, 130,

(8)      1, 9, 45, 175, ...

.............

In every time, we take a evenly distributed series and sum it up to form a new series, then start backward and sum up the new series.

For example, if there are 3 balls, then we use (1), (2), and (3). From (3), 120(The first element > 100) has index 8(from 1, without loss of generality(WLOG)), Then from the 8th element in (2), which 36, we start backward sum-up using (2):

(B)      36, 64, 85, 100, ...

We stop the process once it reaches 100(i.e., >=100, this is because we want to cover 1-100). This series is where we should go, i.e., first try 36, if it's not broken, try 64. If it breaks at floor 36, then it becomes now the case where we have 2 balls and 36 floors. From (2), 36 is the 8th element, this means that we need to start from the 8th element in (1) and sum up backward, ....

If it breaks at 64 and not at 36, then it becomes now the case where we have 2 balls and 64-36=28 balls, if we exclude both ends 64 and 36(since we just tested), we end up 26 balls. Now use the upper bound 28 in 2, we can find the index for (1) and repeat the above.

It's a tedious process, so a program would do the trick for us. The code is largely easy to understand, but there are several cases that twists the logic a little bit:
(i). say floor 5 is broken and there is only one ball, so we have to try from floor 1 to 4, and they are just fine. So logically we know floor 5 is the answer. But the code would print out
something like (5, broken), (4, ok), ...(1, ok).
(ii) say the top floor 5 is the one we are looking for, with only one ball. We have to start from floor 1 on to floor 4. There is no reason to try 5 since it's the top one and every floor below it is ok, so the code has to insert the logic conclusion somewhere.

Noting that though series (1) is evenly distributed(with space 1), it's not the only choice, others are odd number and even numbers(with space 2). However, it's simple to show that when we optimize along space 0, 1, 2, ..., space=1 is the optimal solution(space 0, i.e., the above chinese solution with 10 divided, gives 18; and space 2, i.e., even/odd numbers, give 19).
基于遗传算法的新的异构分布式系统任务调度算法研究(Matlab代码实现)内容概要:本文档围绕基于遗传算法的异构分布式系统任务调度算法展开研究,重点介绍了一种结合遗传算法的新颖优化方法,并通过Matlab代码实现验证其在复杂调度问题中的有效性。文中还涵盖了多种智能优化算法在生产调度、经济调度、车间调度、无人机路径规划、微电网优化等领域的应用案例,展示了从理论建模到仿真实现的完整流程。此外,文档系统梳理了智能优化、机器学习、路径规划、电力系统管理等多个科研方向的技术体系与实际应用场景,强调“借力”工具与创新思维在科研中的重要性。; 适合人群:具备一定Matlab编程基础,从事智能优化、自动化、电力系统、控制工程等相关领域研究的研究生及科研人员,尤其适合正在开展调度优化、路径规划或算法改进类课题的研究者; 使用场景及目标:①学习遗传算法及其他智能优化算法(如粒子群、蜣螂优化、NSGA等)在任务调度中的设计与实现;②掌握Matlab/Simulink在科研仿真中的综合应用;③获取多领域(如微电网、无人机、车间调度)的算法复现与创新思路; 阅读建议:建议按目录顺序系统浏览,重点关注算法原理与代码实现的对应关系,结合提供的网盘资源下载完整代码进行调试与复现,同时注重从已有案例中提炼可迁移的科研方法与创新路径。
【微电网】【创新点】基于非支配排序的蜣螂优化算法NSDBO求解微电网多目标优化调度研究(Matlab代码实现)内容概要:本文提出了一种基于非支配排序的蜣螂优化算法(NSDBO),用于求解微电网多目标优化调度问题。该方法结合非支配排序机制,提升了传统蜣螂优化算法在处理多目标问题时的收敛性和分布性,有效解决了微电网调度中经济成本、碳排放、能源利用率等多个相互冲突目标的优化难题。研究构建了包含风、光、储能等多种分布式能源的微电网模型,并通过Matlab代码实现算法仿真,验证了NSDBO在寻找帕累托最优解集方面的优越性能,相较于其他多目标优化算法表现出更强的搜索能力和稳定性。; 适合人群:具备一定电力系统或优化算法基础,从事新能源、微电网、智能优化等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于微电网能量管理系统的多目标优化调度设计;②作为新型智能优化算法的研究与改进基础,用于解决复杂的多目标工程优化问题;③帮助理解非支配排序机制在进化算法中的集成方法及其在实际系统中的仿真实现。; 阅读建议:建议读者结合Matlab代码深入理解算法实现细节,重点关注非支配排序、拥挤度计算和蜣螂行为模拟的结合方式,并可通过替换目标函数或系统参数进行扩展实验,以掌握算法的适应性与调参技巧。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值