Editorial for TLE '17 Contest 2 P3 - Willson and Migration


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: ZQFMGB12

For the first 30\%, it suffices to consider several cases, since every family of geese moves horizontally. Suppose we check if family i will be within R units of Willson's family.

First, check if the family is already within R units of Willson's family.

Otherwise, suppose Willson's family is moving in one direction. Note that a family can only be within R units of Willson if their starting y coordinates are within R of each other. Suppose the family is heading in the same direction as Willson's family and starts behind Willson. If their speed is faster, then there will eventually be a collision. If their speed is slower, then they will never be close enough. If the family starts ahead of Willson, then there will eventually be a collision if their speed is slower.

Now suppose the family is moving in the opposite direction as Willson. If the family is ahead of Willson, then there will be a collision. Otherwise, there will not.

The second subtask is troll.

For the third subtask, we note that we can find a formula describing the distance between two families with respect to time. If a family moves v units in 1 second in some direction, we can determine the change in x and change in y in 1 second. In particular, we note that for the i^{th} family, the x speed is:

\displaystyle \dfrac{v(x_{i2} - x_{i1})}{\sqrt{(x_{i2} - x_{i1})^2 + (y_{i2} - y_{i1})^2}}

We can come up with a similar formula for the family's y speed. Since distance is the product of speed and time, we can then find the exact location of a family after a certain time. Then, for two families, we want a formula that finds the distance between their two locations after a certain time.

We find that this formula is the square root of a quadratic function, so we can easily find the time in which the two families achieve minimum distance. We then check if this minimum distance is less than R.

Do be wary if the family starts within R units of Willson but moves away, or if the family moves at the same speed and direction as Willson.

Another method of solving the problem involves performing a ternary search on said formula, which passes. A binary search on the "derivative" of the formula however, is extremely inaccurate.

One can also apply knowledge of physics and solve the problem from Willson's frame of reference.

Time Complexity: \mathcal{O}(N)


Comments

There are no comments at the moment.