Posted on 10th May 2015
Urgh, so failure! Some silly (stupid) errors meant my good start of getting problem A out in 16 minutes didn't get me anywhere, as a silly not checking the boundary conditions killed problem B, and not thinking on paper long enough got to problem C. 3 hours and less stress, and it would have been 100/100, but I guess everyone says that about exams. (Of course, given the competition, Round 2 was going to be the end anyway).
As ever, links to: Official Contest Analysis and my code on GitHub.
Problem A, Brattleship: It's in your brother's interest to drag the game out for as long as possible: once he says "hit" we move to a 2nd phase which can only end more quickly.
W-1
. So we hit points W, 2*W, 3*W, ...
W-1
and the end perhaps of shorter length. As soon as you have narrowed the space down to length W
then it's game over, so it's in brat's interest to drag this out.W-1
further goes.W-1
goes, as our next choice can always consistently be a "miss". We can win in W
further goes though (and so this is optimal). We just explore in one fixed direction (left or right). The first time brat says "miss", we know the end of the ship, and we win. As there can only be one further "miss", we do use just W
goes.Problem B, Typewriter Monkey: Monkeys choose uniformly at random from letters (maybe with repeats) for S
goes. You pay them one Banana per copy of the target word (multiple copies can overlap, so if target is "AA" then "AAA" contains 2 copies). You bring the maximum number of Bananas you might need: what is the expected number of bananas you'll have left after payment?
postfix
in the code).count <= 0
not count == 0
) and also forgot that if using the Python functools.lru_cache
then we need to clear the cache (the dictionary of letter probabilities is global, for efficiency, and because dictionaries cannot be hashed by default).Problem C, Less Money, More Problems: Given a set of denominations of money D
, a variable C
which the maximum number of times we can use any coin of one denomination, and V
, we wish to make all values up to and including V
. What is the minimum number of additional demoninations we need to add to D
to make this happen?
E.g. C=1, D=[3,5], V=8
then initially we can make 3, 5, 3+5=8
only. If we add 1
we can now make 1, 3, 4, 5, 6, 8
(and 9, but don't care). Now add 2
and we can make everything, so here the answer is 2.
V
. Stupid...1,2,...,k
but not k+1
. Then we can add a coin of denomination 1, 2, ..., k+1
(assuming they are not in D
already) to allow us to make k+1
. However, the set of new possibilities increases with the value of the coin we add, so the best solution is to add k+1
itself.1,2,...,k, k+1, k+2, ..., k+k+1, 2*(k+1), ..., C*(k+1) + k
so we have a whole "initial interval" we can form. If n <= C*(k+1) +k
is also in D
and we're not yet using it, then we can additionally make all the numbers up to C*n + C*(k+1)+k
.D
, and the remainer of D
consists of larger numbers. We just repeatedly add denominations.D
, so the complexity is something like O( |D| * log2(V) ).