C# – Code Forces 367 – Problem 1, Division 2

Today, on this sunny Saturday I have decided to code a bit in order not to feel guilty in the evening, when I go out. Or something like this. πŸ™‚

I came across of probably the hardest problem, given in CodeForces.com as a first problem in the second divison. Long story short – we have a coordination system and we have to calculate the closest path between two points. Then we have to give them some priority and give the one with the highest result.c#

The story looks like this:

Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi.

Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars.

Input

The first line of the input contains two integers a and b ( - 100 ≀ a, b ≀ 100)Β β€” coordinates of Vasiliy’s home.

The second line contains a single integer n (1 ≀ n ≀ 1000)Β β€” the number of available Beru-taxi cars nearby.

The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≀ xi, yi ≀ 100, 1 ≀ vi ≀ 100)Β β€” the coordinates of the i-th car and its speed.

It’s allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives.

Output

Print a single real valueΒ β€” the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let’s assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .


What have I done?

The trick is not to be afraid in working with the coordination system and to “see”, that here the closest way to Vasiliy is the direct way. At first I thought that if the city is a coordination system, then we have streets like square and etc. However, in this case the second test example (see the link to the problem, I did not paste everything) has shown that Vasiliy lives in a desert and the taxi can reach him driving directly to his point. Whatever…

Here is what I did:

  • Read the input and write the info for the taxis in a list of lists. (first loop).
  • Then in a separate list compute the result of the time, which will be needed for each taxi to reach our hero (second loop).
  • Once we have the list with the results simply print the smallest one (C# is good in handling these tasks).

That’s all. Here comes the code:

The code in GitHub.com.

πŸ˜€

Tagged with: ,