|
Dots in n-dimensional space
|
|
01-12-2010, 08:06 AM
Post: #1
|
|||
|
|||
|
Dots in n-dimensional space
Here is one interesting task.
Given N points in K dimensional space (every point has coordinates K), you should find Euclidean distance between two closest points. Euclidean distance between points A and B in K dimensional space is equal to: SQRT ((A [1]-B [1]) ^ 2 + (A [2]-B [2]) ^ 2 + ... (A [K]-B [K]) ^ 2) That is formula for Euclidean distance in n-dimensional space. Input The standard input is primarily load two numbers N and K (2 <= N <= 900, 1 <= k <= 50). N is the number of points and K dimension of space. The next N lines load the coordinates of N points, and in each line of K coordinates. Each of the coordinates will be in the range [0..10], and will be given to 3 decimals. Output The standard output print a number to 5 decimal, which represents the Euclidean distance between two closest points. Sample Input 4 2 0,000 0,000 1,000 1,000 2,000 0,000 0,000 2,000 Sample Output 1.41421 Solution I made a simple function for distance and i went through all dots and i found the smallest. TPW Code : Code: program dots;Code: # include <iostream>There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
« Next Oldest | Next Newest »
|





