Posted on 24th April 2015
So, I didn't do this one live, as it ran at 2am UK time... I did however, for fun, try this under timed conditions a few days later, and I didn't do great, but got enough to qualify (did A and B with 3 silly mistakes from B, then C small, and stupidly didn't think, and tried my slow algorithm on C large. As large problems are one-shot, it would have been game over, and I'd be around 500 in the ranking.)
As ever, links to: Official Contest Analysis and my code on GitHub.
Problem A, Mushroom Monster: Easy, and my solution doesn't differ from the official analysis.
Problem B, Haircut: Have B
barbers where barber k
always takes \( M_k\) time to perform a haircut. Customers are served by whichever barber is free first, and if there is a choice, the lowest numbered barber goes first. You are N
in the queue. Who served you?
k
has served \[ \Big\lceil \frac{T}{M_k} \Big\rceil = \Big\lfloor \frac{T+M_k-1}{M_k} \Big\rfloor \] customers.k
barbers have served fewer than N
customers, and then a direct simulation to find exactly which barber serves N
.T
exactly, so you know N
is served in at time T
. Then work out how many customers have been served, which barbers are free, and you know the answer without simulation.Problem C, Logging: Have integer lattice points which are trees. Want to know, for each tree, how many other trees do we need to remove so that this tree is then on the boundary of the convex hull of the remaining trees.
The 2D geometry we need: given vectors x=(x_1,x_2) and y=(y_1,y_2) consider the line from x to y extended in either direction. Then a point z=(z_1,z_2) is on the strict left of this line if and only if \[ (y_2-x_2) (z_1-x_1) < (y_1-x_1) (z_2-x_2). \] To see this, I'd argue as follows. Firstly translate x to 0, so subtract x from y and z. Then I want to apply an orientation preserving linear map to move y to the y-axis. This is given by e.g. the matrix \[ \begin{pmatrix} 0 & 0 \\ y_1 & y_2 \end{pmatrix} \] as this matrix has positive determinant (so is orientation preserving) and \[ \begin{pmatrix} y_2 & -y_1 \\ y_1 & y_2 \end{pmatrix} \begin{pmatrix} y_1 \\ y_2 \end{pmatrix} = \begin{pmatrix} 0 \\ y_1^2 + y_2^2 \end{pmatrix} \] so on the positive y-axis. Then z is mapped to \[ \begin{pmatrix} y_2 & -y_1 \\ y_1 & y_2 \end{pmatrix} \begin{pmatrix} z_1 \\ z_2 \end{pmatrix} = \begin{pmatrix} y_2z_1 - y_1z_2 \\ y_1z_1 + y_2z_2 \end{pmatrix} \] and this is on the left if and only if \( y_2z_1 - y_1z_2 < 0 \).