Official

B - Billiards Editorial by evima


We can consider that ball does not bounce at the \(x\)-axis; instead, we can alter the target to the symmetric point with respect to \(x\)-axis, so that we can now consider the intersection of \(x\)-axis and the line connecting the current and target point.

We may find the equation of this line, but instead, considering the delta of \(y\) coordinates, we can see that the lines intersects with \(x\)-axis at the internal division point of two points in the ratio of \(S_y : G_y\), so the desired value can be found by \(\displaystyle{\frac{S_x G_y+G_x S_y}{S_y+G_y}}\), which is the coordinates that divides internally the delta from \(S_x\) to \(G_x\).

Sample Code (C)

Sample Code (Python)

posted:
last update: