使用中位数的N硬币中最轻和最重的硬币

发布于 2025-01-30 05:09:53 字数 86 浏览 4 评论 0原文

假设有一个中位尺度的输入三枚硬币,并在三枚硬币中返回中位数,它不会说明两枚硬币的其余部分。我们如何使用O(NLGN)在硬币中最轻,最重。提供了n个不同的硬币。

Suppose there is a median scale which takes an input of three coins and returns the median among three coins, it won't tell anything about the rest of two coins. How can we find the lightest and heaviest among the coins using O(nlgn).Provided there are n distinct coins.

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

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

发布评论

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

评论(1

纵性 2025-02-06 05:09:53

最轻,最重的硬币是唯一不是任何群体中位数的硬币。

选择任何3个硬币,然后丢弃中位数。重复直到剩下2个。

由于每个操作都会丢弃硬币,因此需要O(n)时间。

The lightest and heaviest coins are the only ones that aren't the median of any group.

Pick any 3 coins and discard the median. Repeat until there are only 2 left.

Since each operation discards a coin, this takes O(n) time.

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