SOJ2658.LineDist

http://soj.me/2658

 

2658. LineDist
 
   
   
 
Time Limit: 1sec    Memory Limit:256MB
Description
In n-dimension space, a line can be determined by two distinct points. Your task is to calculate the distance between the two lines. Distance between two lines is defined as the minimal distance of two points in the two lines respectively. Distance of two points A(x1,x2,…xn) and B(y1,y2,…,yn) is defined as sqrt( (x1-y1)^2 + (x2-y2)^2 + … + (xn-yn)^2 ).
Input
There are several test cases. For each case, there are five lines, the first line contains the integer number n, and then each of the next four lines contains n integer numbers, these data are for four points A, B, C and D. A and B are distinct and determines line AB, C and D are distinct and determines line CD, you should calculate distance between AB and CD.
Constraints: 2 <= n <= 3, other input numbers will be between -1000 and 1000.
Input is ended with n = 0.
Output
Output each result in a single line, with two digit precision after the decimal point.
Sample Input
2
0 0
0 1
1 0
1 1
2
2 0
0 2
-1 0
0 1
3
0 0 0
0 0 1
1 1 0
1 1 1
3
0 0 0
0 0 1
0 1 0
1 1 0
0
Sample Output
1.00
0.00
1.41
1.00

題意:
給兩條2維或者3維的直線求最短距離
大致思路:
對與一點,一條直線上的點與這個固定點的距離是個單峯函數;若這個點在某條線上,那麼這個點與另外一條直線的最短距離也是個單峯函數,所以
用兩重三分。
由於座標在[-1000, 1000],所以最短距離所在點的絕對值會在[0, 10003]內。
程序:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章