SOJ2658.LineDist

1 篇文章 0 订阅

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]内。
程序:
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值