Age | Commit message (Collapse) | Author |
|
Relatively easy since I worked it out in Java and Python. Slight change
of getting rid of the 2 dimensional array, which is probably better and
should have been done in Java and Python. Man, C++ is way more efficient
than Java and Python.
|
|
|
|
Finally Divide and Conquer section is finished. A lot of work but so
much fun!
A few take aways:
1. Be careful when copying code over from Java to C++. Java does
parameter passing through reference as default, but I forgot to add "&"
in C++ code, which caused my code not passing earlier;
2. Avoid unnecessary calculation. For example, the sqrt calculation is
not necessary, until the last step. Avoiding that in my Python code
saved a lot of time.
3. It seems that preallocate vector size, if you know beforehand, is a
good idea.
Woohoo, onto the next section!
|
|
|
|
Worked out the algo earlier, but the challenge was to learn to use
vector in C++ and vector slicing. I got bad allocation error initially
due to misunderstanding that the end is not inclusive: that is,
vector.begin() + m reaches vector.begin() + m-1.
|
|
|
|
Wow, it took awhile to finish. Work has been busy and I haven't had time
to hack...
|
|
It was interesting that int in jave has a bigger range than int in C++
Java: https://cs.fit.edu/~ryan/java/language/java-data.html
C++: https://stackoverflow.com/questions/1819189/what-range-of-values-can-integer-types-store-in-c
I used vector<int> initially, which failed on grader's test case 17/36.
Changing that to vector<long> fixed it! Also interesting that recursive
approach appears to be slightly faster with slighter bigger memory
usage.
|
|
|
|
More practice with C++ vector.
|
|
Really fun to implement it in C++. Learned std::sort, std::unique, ==
overloading for struct for std::unique to work. Good stuff!
|
|
also known as maximize online ad revenue in exercise pdf file.
|
|
Good exercise. Learned C++ vector usage, and the ASSERT_NEAR macro for
testing floats/doubles. Lots of fun.
|
|
I noticed that in this case, it was really simple, because I pretty much
copied the code from Java.
|
|
|
|
This concludes the second module of Algorithmic Design and Techniques
from edX. I had a lot of fun doing it. It's challenging and I learned a
lot!
|
|
|
|
This was so much fun! I'm glad I did it with Python, Java, and C++, in
that order. I learned so much through the process: typing, overflow,
BigInteger, and ended up not needing BigInteger! Yay!!!
|
|
|
|
|
|
|
|
|
|
|
|
|