2012年10月31日

一道概率题

摘要: 问题:一副扑克牌54张,随机打乱之后排成一叠,从上到下一次翻(摸)一张牌,直到翻到一张k为止。问:下一张牌是黑桃k的概率大还是黑桃3的概率大?分析一下这个题目,可以发现题目有歧义(既然是条件概率,那已知的条件有哪些呢?):题目理解1。如果只有一个人在翻牌,那他肯定知道第一张k是不是黑k,也肯定知道黑3有没有翻出来,也肯定知道还剩多少张牌。有了这些数据,算下一张牌是黑3还是黑k的概率就容易些了。题目理解2。如果有两个人,一个人翻牌,另一个人不许看。当翻牌的人翻出了第一张k,而且不告诉另一个人是什么k,且不告诉他翻了多少张之类的。仅仅告诉另一个人翻出了一张k。这时问另外一个人下一张牌是黑3的概率大 阅读全文

posted @ 2012-10-31 22:04 Torstan 阅读(449) 评论(0) 推荐(0) 编辑

2012年10月29日

mutex and condition variable

摘要: mutex and condition variable 阅读全文

posted @ 2012-10-29 16:44 Torstan 阅读(83) 评论(0) 推荐(0) 编辑

2012年10月23日

virtual inheritance

摘要: Virtual inheritance is used to solve the problem of diamonds inheritance, 2 instance of base objects, in multiple inheritance. With the knowledge on c++ object model, we can understand virtual inheritance easily. Here is a sample code.#include<iostream>using namespace std;class Point2D_IF{ pub 阅读全文

posted @ 2012-10-23 18:20 Torstan 阅读(198) 评论(0) 推荐(0) 编辑

2012年10月22日

virtual destructor

摘要: code 1.#include <iostream>using namespace std;class Base { public: Base() {cout<<"Base constructor"<<endl;} ~Base() {cout<<"Base destructor"<<endl;}};class Derived:public Base{ public: Derived() {cout<<"Derived constructor"<<end 阅读全文

posted @ 2012-10-22 22:33 Torstan 阅读(167) 评论(0) 推荐(0) 编辑

2012年9月24日

thread local storage

摘要: Thread local storage allows multi-threaded applications to have a separate instance of a given data item for each thread. Where a single-threaded application would use static or global data, this could lead to contention, dead lock or data corruption in a multi-threaded application. One example is t 阅读全文

posted @ 2012-09-24 20:46 Torstan 阅读(240) 评论(0) 推荐(0) 编辑

2012年9月17日

notes on relations

摘要: Definition 1. Let A and B be sets. A binary relation from A to B is a subset of A X B.In other words, a binary relation from A to B is a set R of ordered pair in which the first element of each ordered pair comes from A and the second element comes from B. We use aRa to denote that (a, b) belongs to 阅读全文

posted @ 2012-09-17 19:22 Torstan 阅读(225) 评论(0) 推荐(0) 编辑

2012年9月7日

mathematical induction and well-ordering principle

摘要: 1. Mathematical inductionMathematical induction can be used to prove the statement that asserts P(n) is true for all positive integers n, where P(n) i... 阅读全文

posted @ 2012-09-07 20:20 Torstan 阅读(723) 评论(0) 推荐(0) 编辑

2012年8月18日

两道概率算法题

摘要: 题目1. 给定一个包含n行数据的文件(n未知),要求设计一个算法,只遍历文件一遍就能等概率地输出某一行。即,每行被输出的概率是相等的(1/n,n未知)。假设文件可能会很大,内存有限,不能保存所有的文件数据。题目2. n个数据排除一行,即数据Ci在位置Li, 1<=i<=n,设计一个算法把数据打乱,使得每个数据在等概率地出现在每个位置,即 p(Ci, Lj)=1/n, 其中 1<=i<=n, 1<=j<=n.答案见下方-------------------------------------------------------------------解答1.【 阅读全文

posted @ 2012-08-18 15:20 Torstan 阅读(250) 评论(0) 推荐(0) 编辑

2012年7月23日

understanding assembly code (2)

摘要: What is this topic about?It is a study on the difference betweeen a function returning a vector and a function accepting a reference to a vector as a parameter.[torstan]$ more vec.cc#include<vector>using namespace std;vector<int> f(){ vector<int> v; v.push_back(2); return v;}/*g++ 阅读全文

posted @ 2012-07-23 19:21 Torstan 阅读(425) 评论(0) 推荐(0) 编辑

2012年7月22日

understanding assembly code (1)

摘要: 1) BackgroundSometimes, when we meet with a problem very hard to explain or understand, we can try more powerful tools, e.g. math or assembly code. In... 阅读全文

posted @ 2012-07-22 21:18 Torstan 阅读(563) 评论(0) 推荐(0) 编辑

导航