Wednesday, February 27, 2013

Competitive programming skillset links

This link is on the dot. Must know if you really want to make progress. I was planning to construct one, now, I can just reuse.
I landed up there from uHunt training series.
BTW, I have their book: Competitive Programming 2.

UVA 10035 - Primary Arithmetic : Accepted

UVA 10035 - Primary Arithmetic accepted :) sweet :) but, it was on the 7th attempt.
Tip: if you are printing the output, add the '\n' after every output.
I tried solving it in two ways: 
1. Taking the numbers into char arrays:
The char array solution was difficult to code because I reversed each array, started to iterate until the array with min length, then traverse until the end of the longer array to get to the final answer. I made a number of mistakes here:
* Instead of iterating over revNum1, I iterated of num1
* The minLen was using the length of the larger array (mainly due to copy paste)
* I had to construct quite a few testcases to assure myself of the correctness
2. Taking the numbers as numbers:
This was simpler to code and I knew that I had the correct answer without crossing my fingers unlike the previous option. Keeping the implementation simpler assures you of the 'Accepted' state and you know that a 'WA' in this case means that something is wrong in the output format and not your code :-)
Also I could reuse the logic from my earlier solution to 10018 - Reverse and Add.

Tuesday, February 19, 2013

UVA 469 Wetlands of Florida Accepted

Solved yet another UVA problem: Wetlands of Florida. Feels good. One odd thing in this problem was handling the input. In the solution, I initially went with the recursive DFS which failed on my test case containing a 99x99 'W' wetlands map. I changed to follow one of the good implementations of Chefhack by msasha. Some implementations are so very user friendly than machine friendly.
Many thanks to the codechef CHEFHACK editorial to list this problem.
Email excerpt from the online judge: "Your submission with number 11309634 for the problem 469 - Wetlands of Florida has succeeded with verdict Accepted."

Saturday, February 16, 2013

UVA 352 Seasonal War : Accepted :)

This link from CodeChef is the editorial for CHEFHACK. It had the link to another similar problem in UVA which is Seasonal War. I started to solve the problem and had just one thing that sounded unclear to me: "Cells with adjacent sides on common vertices, which contain binary ones, comprise one war eagle. A very large image of one war eagle might contain all ones." Looking at the sample cases it became clear. Coded the changes, created my own test cases and seeing that all was well, I submitted the solution. This is what the judge told: "Your submission with number 11293947 for the problem 352 - The Seasonal War has succeeded with verdict Accepted."

Monday, February 4, 2013

Link with 4 interesting problems I saw while visiting uva.onlinejudge.org...

I have made uva.onlinejudge.org my homepage in Firefox and when I went there yesterday, I saw this link. I checked the link and it had 4 problems: Different (very easy), Reverse Binary (easy), Coastal length (medium) and CatVsDog (Hard)

I was able to solve Different and Reverse binary in one attempt. Then, I started to code for Coastal length and found some interesting cases to solve. Need to find the right algorithm for this problem.

Saturday, February 2, 2013

CodeChef:February2013 challenge: BUY1GET1 solved

BUY1GET1 solved. There is nothing much to say except that people have solved this problem using much lesser memory!