-
Addresses on 64 and 32 OS are different, so you have to be careful when your program have to deal with address. For example, if you take the difference of two pointers/iterators, you should type
std::ptrdiff_t
(which is essentially a singed integer type). Using an arbitrary integer type …
Automated Verizon Phone Bill (Continued)
I have switched to the "Share Everything" plan of Verizon two weeks ago, and I got a little complex bill this month due to people leaving and joining my family plan. My ruby program for parsing phone bill still works well. It is actually surprising smarter than I thought on …
String in C++11
-
auto s = "abcd"
creatsconst char *
not string, so useauto
with caution. -
Since a string in C++ is an array of chars, you can operate it like an array. For example, you can use range-based for loop and so on.
-
It is recommended that you use
std::string
in …
Make Eclipse Support C++11
-
Make a new C++ project
-
Default options for everything
-
Once created, right-click the project and go to "Properties"
-
C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous -> Other Flags. Put -std=c++0x at the end.
-
C++ General -> Paths and Symbols -> Symbols -> GNU C++. Click "Add..." and paste
__GXX_EXPERIMENTAL_CXX0X__ …
How Many Balls Do We Need?
If we randomly put balls into \(m(\ge1)\) boxes until \(n(\le m)\) of them are occupied, what is the expectation of the number of balls needed?
See my neat solution here.
Number of Records?
Suppose there are \(n\) distinct numbers \(x_1,\ldots, x_n\), and \(y_1, \ldots, y_n\) is a random permutations of them. If \(\exists k\) such that \(y_k<y_i, \forall 1\le i<k\), then we say that \(y_k\) is a record (we always count \(y_1\) as a record). What is the expected …