QuestToSolve.com RSS
http://www.questtosolve.com
The last 3 problem solutions from both of us.en-caCopyright 2009 QuestToSolve.comhttp://www.questtosolve.com/rss|=========================================|Peter's SolutionsProblem Number: 10878 (Decode the tape)Solution:
Each row on the tape is a binary sequence, that represents the ascii value of a given character.
Ignore the lines | and _ which define the outer perimeter of the tape, and ignore the periods as well.
Take the input in, and remove all the unnecessary characters, then change the spaces to zeros and o's to 1's.
Output the characters corresponding to the given ascii values, but do not print out a new line after the input!!!
http://www.questtosolve.com/browse.php?pid=10878
Problem Number: 10922 (2 the 9s)Solution:
Literally define a recursive function that takes integers a and b.
If a < 10, return b if a % 9 == 0, and return -1 otherwise.
If a >= 10, sum its digits and return recursivefunction(sum, b+1)
Then, in your normal function, sum the digits of the input right away, and just return recursivefunction(sum, 1).
http://www.questtosolve.com/browse.php?pid=10922
Problem Number: 11204 (Musical instruments)Solution:
I completely overthought this problem the first time, and the second time.
It's simply a combinatorics solution. Create an instruments array, and increment the elements corresponding to the students' first choices. The other choices are irrelevant.
Now, just go through the array, and multiply all the elements > 1 together. There's your answer!
This is because for each instrument in competition, there are n students that could have it (where n is the number of students with it as a first priority).
From there it's simply the combinations of students for each instrument.
At first I thought this was a DP - although I'm sure you could probably think one up. Then I misread the question, and thought that in addition to the correct solution above, you had to multiply THAT by all the combinations of students who didn't get the instrument they wanted - getting instruments they don't want.
http://www.questtosolve.com/browse.php?pid=11204
|=========================================|Wesley's SolutionsProblem Number: 1103 (Ancient Messages)Solution:
The key thing to notice in this problem is that each of the 6 shapes has a different number of holes. "Was" has no holes, "Ankh" has one, ..., "Djed" has five.
So this problem boils down to finding contiguous sets of black pixels and determining how many holes are inside.
First, look for white pixels on the border of the image. These are definitely background pixels. Floodfill all white pixels from these to find all background pixels.
Now we'll do a double-floodfill. First, scan the image for black pixels. When you find one, floodfill outwards looking for black pixels, and white pixels that aren't part of the background. When you find such a white pixel, floodfill for all white pixels that it's connected to, and mark this as one hole. Then, go back to flooding black pixels.
http://www.questtosolve.com/browse.php?pid=1103
Problem Number: 10618 (Tango Tango Insurrection)Solution:
Our DP will be a series of arrays of size [4][4][3][70].
f(l, r, m, k) is the amount of energy it takes to complete the rest of dance given that you've completed k steps so far, your left foot is on square l, your right foot is on square r, and m is a value (0, 1, or 2) that represents which foot (if any) moved in the last step.
The convention I use for l and r is 0 = Up, 1 = Left, 2 = Right, 3 = Down.
For m I use 0 = no foot moved, 1 = Left, 2 = Right.
So, we want to determine f(1, 2, 0, 0), and return the appropriate sequence of actions. At each step, there are two cases:
Case 1: The next step is '.'
In this case, try moving your left foot to all four squares, and then try moving your right foot to all four squares. Nothing is going to be tapped, but you can use this pause in the music to reposition yourself. If you move a foot, make sure to output the foot that moved, even though it didn't tap.
Case 2: The next step is 'U', 'L', 'R' or 'D':
In this case, try moving your left foot to the appropriate square, and try moving your right foot to that square as well.
In both cases, make sure not to allow any illegal moves.
I recommend having three parallel arrays. Each is indexed as mentioned above, by (l, r, m, k). The first array, COST, is the standard DP array that keeps track of how much energy it takes to complete the dance from the given state. The second array, NEXT, keeps track of some integer or object that points to the next state in the path, and the third array, MOVE, keeps track of what move was taken.
For example, consider the input "LUR". We go through the following transitions to get the output "LRL":
l r m k
1 2 0 0 (move is "L")
1 2 1 1 (move is "R")
1 0 2 2 (move is "L")
2 0 1 3 (sequence is finished)
And the arrays look like this:
NEXT[1][2][0][0] = (1, 2, 1, 1)
MOVE[1][2][0][0] = 'L'
COST[1][2][0][0] = 3
NEXT[1][2][1][1] = (1, 0, 2, 2)
MOVE[1][2][1][1] = 'R'
COST[1][2][1][1] = 2
NEXT[1][0][2][2] = (2, 0, 1, 3)
MOVE[1][0][2][2] = 'L'
COST[1][0][2][2] = 1
At the end of the DP, use the information in NEXT to traverse through the optimal states, and use the information in MOVE to print out the move sequence.
http://www.questtosolve.com/browse.php?pid=10618
Problem Number: 10262 (Suffidromes)Solution:
Try all reversed prefixes of each string as possible suffixes, in order of increasing length, and lexicographic earliness. So, for the input:
andrew
wesley
Try "", "a", "w", "ew", "na", "dna", "sew", etc.
For each suffix, try appending it to both strings. If it turns only one into a palindrome, then that's your answer.
If at the end you find no solution, there's one more step to try. We may have a case like:
a
<blank line>
In this case, the solution is "b". Or we might have:
a
aa
In this case, "ba" is the correct suffix.
Let S1 be the smaller string, and S2 be the larger string. If both are the same length, then it doesn't matter which you pick. Try 26 more suffixes, "a"+rev(S1) through "z"+rev(S1), where rev(S1) is S1 reversed.
If there are still no solutions after this step, then print "No solution."
http://www.questtosolve.com/browse.php?pid=10262