008. N-Dimensional Distance
008. N-Dimensional Distance
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Calculate the distance between two points of a specified dimension. The common distance formula still applies to higher dimensional points with a small modification. You will input two points and display the distance between them as you normally would with the distance formula.
The n-dimensional distance formula can be expressed as
or in other terms:
Remember that math.sqrt will calculate the square root of a number (you also have to add the line import math at the top of the program).
Input
The first line contains the dimension D between 2 and 500. Then, D test cases will follow.
Each test case N will consist of two lines: the value of the first point, and the value of the second point, in the Nth dimension.
Each of these values is an integer between -5000 and 5000, inclusive.
Output
A decimal number N representing the distance between the two points. Do not round your answer.
Examples
input
Copy
2 1 1 1 2
output
Copy
1.0
input
Copy
3 7 4 3 17 6 2
output
Copy
14.866068747318506
input
Copy
4 -2367 -2873 -4279 -2321 -1302 -1341 -2893 651
output
Copy
4080.5951771769764
Comments
Post a Comment
Please give us your valuable feedback