Computer Science Canada Round 2 questions |
Author: | Panphobia [ Wed Nov 28, 2012 7:57 pm ] |
Post subject: | Round 2 questions |
Could someone please explain what algorithms we needed to use for question 4 and 5 on the dwite contest, that would be nice, I know the rest of it, but my team had trouble with the last two, we knew the logic, just not exactly how to implement it. |
Author: | Tony [ Wed Nov 28, 2012 10:40 pm ] |
Post subject: | RE:Round 2 questions |
Question 4 is about maintaining a list of cards that have not yet been used in the answer deck. The note after the sample explains most of it: Quote: Notes: for the first case, going backwards from the solution: the first card has value 2, and there is only 1 card with greater value after it (3). Second card has value 1, and there is only 1 card with greater value after it (3). The last card has value of 3, and there are no cards with greater value. So the input of "1 1 0" checks out. Going the other way: possible cards (sorted order): [1,2,3] answer deck: [] what we know about the first card: "there is 1 card with greater value than it." action: move the 2nd last card from possible list into the answer deck. now the state is: possible: [1,3] answer: [2] at this point the steps repeat. possible: [3] answer: [2,1] possible: [] answer: [2,1,3] ---------- For Q5, a http://en.wikipedia.org/wiki/Greedy_algorithm will produce an optimal result. E.g. you must monitor the first car, so place the first guard as far away as possible, while he can still monitor this car. Remove all of the cars that he can observe from the list. Repeat until the list is empty. |
Author: | Panphobia [ Wed Nov 28, 2012 11:14 pm ] |
Post subject: | RE:Round 2 questions |
ohhhhh if only i read it right tony you're a lifesaver |
Author: | Panphobia [ Wed Nov 28, 2012 11:22 pm ] |
Post subject: | RE:Round 2 questions |
haha now I have to find out how to use a greedy algorithm, funn :DDDDDDD, I was expecting a grid/maze type question, because that is all i practiced, here comes dwite, NO GRID/MAZE type question lol |