阿里巴巴实习笔试

 参见:http://blog.csdn.net/doc_sgl/article/details/8888904

附:

  1. 士兵两两通话,最小通话次数
比如说假设有k个种子(k个人进行消息融合)
算法就是:
f(n) = n-k + f(k) + n-k
      = 2n + f(k) -2k
就是说要找使f(k) - 2k最小的k
而最终f(k) - 2k肯定是个常数
f(n)随n单增,从k=1开始肯定能找到使f(k) - 2k最小的k
于是找到k=4时,f(k) - 2k = -4最小
但最终发现只要n, k >= 4,无论k等于几,f(n) = 2n - 4
所以与k为多少无关
 
A popular formulation assumes there are n people, each one of whom knows a scandal which is not known to any of the others. They communicate by telephone, and whenever two people place a call, they pass on to each other as many scandals as they know. How many calls are needed before everyone knows about all the scandals? Denoting the scandal-spreaders as A, B, C, and D, a solution for n=4  is given by {A,B},{C,D} , {A,C}, {B,D}. The solution can then be generalized to n>4 by adding the pair {A,X} to the beginning and end of the previous solution, i.e.,{A,E} , {A,B}, {C,D}, {A,C}, {B,D}, {A,E}.
 
Let f(n) be the number of minimum calls necessary to complete gossiping among n people, where any pair of people may call each other. Then f(1)=0, f(2) = 1, f(3) = 3, and
f(n) = 2n-4,  for n>=4.
 This result was proved by (Tijdeman 1971), as well as many others.
In the case of one-way communication ("polarized telephones"), e.g., where communication is done by letters or telegrams, the graph becomes a directed graph and the minimum number of calls becomes
f(n) = 2n-2, for n>=4.
 (Harary and Schwenk 1974).
 
Gossiping (which is also called total exchange or all-to-all communication): http://mathworld.wolfram.com/Gossiping.html
 
 
 
 
posted @ 2013-05-20 13:08  Avril  阅读(815)  评论(0编辑  收藏  举报