Wednesday, July 5, 2006 Match summary This match continued the streak of Burunduks. With the best overall score and with 3 successful submissions, Burunduk3 took first place, Burunduk2 took second place, despite losing his 250 and getting no challenges he lost by less than 50 points. Impressive! Rounding out 3rd place was Weiqi. The ProblemsTVSizeUsed as: Level One:
This problem appeared to be really tricky for most of the coders. The main source of the troubles was the classical floating point imprecision (misof's article on this topic is going to become a classic among TopCoder members). The simplest way of solving this problem is to directly follow the instructions double h = sqrt(sqr((double)diagonal) / (sqr(((double)width) / height) + 1)); double w = sqrt(sqr((double)diagonal) / (sqr(((double)height) / width) + 1)); vectorand round both h and w down to the nearest integer. Unfortunately for lots of our coders, this approach is wrong. Even a small imprecision can be fatal for your solution  value of h equal, for example, to 2.99999 instead of 3 will be rounded down to 2 and cause your solution to fail. Fortunately, this problem can be solved without using any floating point numbers at all. The problem asks us to find the biggest integer number h such that h <= (diagonal * height / hypoth), where hypoth = sqrt(height^{2} + width^{2}).Squaring this formula we can get the following one: h * h <= (diagonal * height)^{2} / (height^{2} + width^{2}),or, in other words, (height^{2} + width^{2}) * h * h <= (diagonal * height)^{2},Having this formula, we can easily find h (don't forget to use long variables to avoid integer overflow): for (long i = 0; ; i++) if ((height * height + width * width) * i * i > (diagonal * height * diagonal * height) return i  1;SuperSort Used as: Level Two:
This problem was fairly simple. Given a string of words, spaces and punctuation, sort the words while preserving the spaces and punctuation. In pseudocode, all one needs to do is locate each word, extract it and replace it with a place holder. Store each word in a container and sort it; both C++ and Java provide mechanisms for sorting so you shouldn't have to write your own sort algorithm. With this sorted list of words, iterate across the original string (with the place holders) and build a new string. If the current position of the original string has a place holder add the next sorted word, otherwise, add the current character to the return string. My solution is show below. public String wordSort(String sentence) { int characterIndex = 0; int wordIndex = 0; ListTextEditorNavigation Used as: Level Three:
The problem asked for the fewest keystrokes required to navigate from the starting position in the given source to the ending position. This is a classical example of a Breadth First Search (BFS). I solved this problem using a 50 by 50 array of int with each position holding the minimal keystrokes possible to get to that point. As a detail of implementation, we can make all strings of the text to be of the same length. This makes coding and checking for boundaries a bit easier. To start the BFS, we need to initialize our time array. We set the time for the starting position to 0 (because we can get it in 0 steps) and all other positions to an impossibly high value like 1000000. Also, we add the starting position to a queue. The program continues working until the queue is empty trying each of the possible 10 moves at the current position, adding new positions when performing the move causes the table to be updated with a new minimum. Finally, one returns the entry in the table indexed by the ending position. Java implementation follows: QueueDespite the efforts of the problem statement, it wasn't clear to some people that one could view the columns as expanding from 0 (the leftmost column) to infinity (the rightmost column); although 50 columns was all you needed. Also, some people had a difficult time interpreting word left and word right. 
