Thursday, June 27, 2013

Win32 no more flicker

Thanks to this blog, solved that flicker problem by:

  1. Painting to a back buffer instead of directly to screen
  2. Overriding WM_ERASEBKGND with "return true" so that it doesn't erase the background every second/every time the screen is invalidated.

Code

Next, to get rid of the black background.

Wednesday, June 26, 2013

Codechef Jun 2013 Elephants (C++)

This code is simply a direct port from Python to C++. My Python submission gave a "time limit exceeded" error, while my C++ submission is perfectly accepted. Is Python really that slow?

Tuesday, June 25, 2013

More Win32 fun

Managed to set a timer to update the text on the screen every second, however, the window does not wipe itself clean after every update.

Code

After much research, came upon this solution: http://msdn.microsoft.com/en-us/library/ms632599(VS.85).aspx#layered

Instead of I used That solved it. Code

Codechef June 2013 Elephants

Wednesday, June 19, 2013

Win32 programming: random messages on the screen

I've always wondered how typical keygen programs, when run, doesn't create a window on screen. Or rather, technically, it's still a window, but there are no title bars, no _ □ X buttons, no borders, and even the background is transparent. Well, after viewing some basic Win32 tutorials and meddling with windows style I managed to satisfy my curiosity:
Next step, to make it drag-able!

Tuesday, June 18, 2013

Codechef May 2013 WitMath

I thought that by referencing the editorial and following faithfully I could have the solution out in minutes. Turned out to be hours..totally forgot how to do repeated squaring. Good revision, this was.

Monday, June 17, 2013

Codechef June 2013 Delish

I worked for hours on this one, just for my solution to be rejected. =( But the hard work paid off, my solution came very close to the one in the editorial =) This one didn't get accepted: Did my correction and got it accepted:

Codechef June 2013 Wstring

Seen the editorial, the algorithm described is exactly the same as what I did..but my solution is not accepted. I don't know why ='(

Codechef June 2013 Predictopus

Was wondering for a while if the each test case is accumulative from the previous...turned out it was not. Accepted!

Codechef June 2013 Lapindromes

Accepted!

Friday, June 14, 2013

Google Code Jam 2009, Round 1C, Problem A: All Your Base

Here is a nice summary of the approach to this problem.
The above problem statement, requires the output to be the minimum possible number. The first step is to understand that the number would be smaller if you take the smallest possible 'Base System' for the number. To find the base system that you want, you would have to find the number of unique symbols in the input string. If there are 2 'Unique' symbols in the string, take it as 'Base 2' system. If there are 10 unique symbols, take it as 'Base 10 (Decimal)' system.....and so on. Since the 'Unary System' is not used, ignore that. 
After that, we need to find how we can make the sum, as minimal as possible. Since we don't know which digit stands for what, we have to make a decision for each symbol, so as to make the number, as small as possible. Since the left most digit carries more weight, this digit should be multiplied by the smallest digit. But since the left-most digit can't be zero (0), make it '1'. Use the Zero (0) for the second left-most digit (if there is 2nd digit in the number). Then use '2' for the third left most digit (if it is unique), '3' for the 4th left most digit (if it is unique)..and so on, unitl the end of the string with symbols. 
^^

Thursday, June 13, 2013

ACM 103 Stacking Boxes

Greedy problem. For each box, sort each dimension from biggest to smallest. Then, sort all boxes from smallest to biggest. Apply some dynamic programming and viola!