- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在 n
人中,“名人”被定义为某人人尽皆知,却无人知晓。这问题是识别名人,如果有的话,通过询问仅以形式提问,“对不起,你认识这个人吗那边?”(假设所有答案都是正确的,甚至那个名人也会回答。)目标是尽量减少问题的数量。
这里有没有比明显的O(n^2)
阶数小的解?
最佳答案
利用名人问题的分析here
Brute-force solution. The graph has at most
n(n-1)
edges, and we can compute it by asking a question for each potential edge. At this point, we can check whether a vertex is a sink by computing its indegree and its outdegree. This brute-force solution asksn(n-1)
questions. Next we show how to to do this with at most3(n-1)
questions and linear place.An elegant solution. Our algorithm consists of two phases: in the elimination phase, we eliminate all but one person from being the celebrity; in the verification phase we check whether this one remaining person is indeed a celebrity. The elimination phase maintains a list of possible celebrities. Initially it contains all
n
people. In each iteration, we delete one person from the list. We exploit the following key observation: if person1
knows person2
, then person1
is not a celebrity; if person1
does not know person2
, then person2
is not a celebrity. Thus, by asking person1
if he knows person2
, we can eliminate either person1
or person2
from the list of possible celebrities. We can use this idea repeatedly to eliminate all people but one, say personp
. We now verify by brute force whetherp
is a celebrity: for every other personi
, we ask personp
whether he knows personi
, and we ask personsi
whether they know personp
. If personp
always answers no, and the other people always answer yes, the we declare personp
as the celebrity. Otherwise, we conclude there is no celebrity in this group.
关于algorithm - "celebrity"算法的最优解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29814436/
我正在尝试在r中编写代码,以便找到单变量正态分布的最大似然(而不是对数似然)值。我知道还有其他方法,但是我需要深入了解数值优化才能进行进一步的工作。当我调用'optim'函数时,它似乎根本不会进行迭代
最近我一直在用 php + mysql 做一个相当大的项目。现在我担心我的 mysql。我应该怎么做才能使我的 mysql 尽可能优化?把你知道的都说出来,我将非常感激。 第二个问题,我在每次加载页面
我不太了解 InitializeCriticalSectionAndSpinCount 的文档: http://msdn.microsoft.com/en-us/library/windows/des
我们公司有几种不同的获取潜在客户的方式,以及我们处理的几种类型的潜在客户。每种类型的潜在客户之间只有微小的差异,并且大部分信息与一种或多种其他潜在客户类型共享或相关。我和我的团队正在尝试使用 Solr
ϵ-贪婪策略 我知道 Q-learning 算法应该尝试在探索和利用之间取得平衡。由于我是该领域的初学者,因此我想实现一个简单版本的探索/利用行为。最佳 epsilon 值 我的实现使用 ϵ 贪婪策略
我是一名优秀的程序员,十分优秀!