#K90617. Nearest Tree Distance
Nearest Tree Distance
Nearest Tree Distance
You are given a set of N trees on a 2D plane and Q queries where each query represents the coordinates of a house. For each house, compute the minimum Euclidean distance to any tree. The Euclidean distance between two points \((x_1, y_1)\) and \((x_2, y_2)\) is given by the formula: $$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}.$$ Finally, output the computed distance for each query, formatted to 6 decimal places.
inputFormat
The input is read from standard input (stdin
) and is structured as follows:
- The first line contains an integer N, the number of trees.
- The next N lines each contain two integers, representing the x and y coordinates of each tree.
- The following line contains an integer Q, the number of queries.
- The next Q lines each contain two integers, representing the x and y coordinates of a house.
outputFormat
For each query, output the minimum Euclidean distance from the house to any tree, with exactly 6 decimal places. Each result should be printed on a new line to stdout
.
3
1 2
4 6
7 8
2
2 3
5 5
1.414214
1.414214
</p>