n枚硬币。哪个是假的?

发布于 2024-09-25 16:38:49 字数 359 浏览 2 评论 0原文

可能的重复:
查找最小数量的算法从一组 n 个球中找出有缺陷的球所需的称重

我们有 n 个硬币。其中一件是假的,是更重还是更轻(我们不知道)。我们有带 2 个盘子的秤。我们怎样才能在p步中获得假币呢?

你能帮我写一个这样的程序吗?不需要完整的计划,只需想法。

谢谢。

Possible Duplicate:
Algorithm to find minimum number of weighings required to find defective ball from a set of n balls

We have n coins. One of them is fake, which is heavier or lighter (we don't know). We have scales with 2 plates. How can we get the fake coin in p moves?

Can you give me a hand for writing such a program? No need a whole program, just ideas.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

偏爱你一生 2024-10-02 16:38:49

我记得对 n=12 和 13 的这个问题进行了求解,部分是手工求解,最后用程序求解。我不知道如何解决一般的 n...但我知道如何开始 - 通过考虑 n 的小值并通过手。

我怀疑本质上有一些模式可以为此递归使用......但是您会发现用笔和纸发现小值(例如,n=4 到 7)比通过编码更容易发现它们。

I remember solving this for n=12 and 13, partly by hand and then with a program at the end. I don't know how I would solve it for a general n... but I know how I'd start - by considering small values of n and doing it by hand.

I suspect there are essentially patterns that can be used recursively for this... but you'll find them much easier to discover with pen and paper for small values (n=4 to 7, for example) than by coding.

怪我太投入 2024-10-02 16:38:49

将硬币放在两侧,真币会相互平衡,假币会使秤朝任何一个方向移动。当天平不平衡时,您刚放的两枚硬币中的一枚是假的,用一枚真硬币试一试。

如果硬币是你收到的物品,那么你应该能够在程序中很容易地做到这一点。

Put coins on each side, the real ones will balance each other out, the fake will make the scale go either way. When the scales aren't balanced, one of the 2 you just put on is fake, try each against a real coin.

If the coins are objects you're handed, then you should be able to do that in a program quite easily.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文