05 2012 档案

一道概率算法
摘要:问题:一个API,以概率p输出1,以概率1-p输出0,请你设计以算法,call这个API,以概率1/2输出1,以概率1/2输出0答案:连续call 2次这个api, 如果输出序列是01,那么就输出0,如果是10,那么就输出1,是其它情况(00,11),重做一遍前面的步骤算法的证明:第一轮call 2次这个api,产生的序列的概率是01 (1-p)*p, 10 p*(1-p), 00 (1-p)^2, 11 p^2,按照我们的算法(答案),以 (1-p)*p的概率输出0,以p*(1-p)的概率输出1,以(1-p)^2+p^2的概率重新执行我们的算法,此时输出0的概率是(1-p)*p + ((1- 阅读全文

posted @ 2012-05-21 15:54 Torstan 阅读(141) 评论(0) 推荐(0) 编辑

favourite programming quotes
摘要:1) Everything should be made as simple as possible, but no simpler.-Albert Einstein2) If debugging is the process of removing software bugs, then programming must be the process of putting them in.-E.W.Dijkstra3) There are two ways of constructing software design. One way to make it so simple that t 阅读全文

posted @ 2012-05-05 12:18 Torstan 阅读(107) 评论(0) 推荐(0) 编辑

how does malloc/free work?
摘要:Here is the answer I got from Internet.Here's a simple, vague answer:Your process has a region of memory, from address x to address y, called the heap. All your malloc'd data lives in this area. malloc() keeps some data structure, let's say a list, of all the free chunks of space in the 阅读全文

posted @ 2012-05-02 19:17 Torstan 阅读(284) 评论(0) 推荐(0) 编辑

导航

点击右上角即可分享
微信分享提示