HDU 6097 数学几何

探讨了给定圆及圆内两点时,寻找圆上一点使该点到两给定点距离和最小的问题。利用反演点的概念,通过转换问题视角找到最优解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mindis

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1519    Accepted Submission(s): 237
Special Judge


Problem Description
The center coordinate of the circle C is O, the coordinate of O is (0,0) , and the radius is r.
P and Q are two points not outside the circle, and PO = QO.
You need to find a point D on the circle, which makes  PD+QD  minimum.
Output minimum distance sum.
 

Input
The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with r : the radius of the circle C.
Next two line each line contains two integers x , y denotes the coordinate of P and Q.

Limits
T500000
100x,y100
1r100
 

Output
For each case output one line denotes the answer.
The answer will be checked correct if its absolute or relative error doesn't exceed  106 .
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if  |ab|max(1,b)106 .
 

Sample Input
  
4 4 4 0 0 4 4 0 3 3 0 4 0 2 2 0 4 0 1 1 0
 

Sample Output
  
5.6568543 5.6568543 5.8945030 6.7359174
 

Source
 


题意 : 给一个圆,两个点,这两个点不在圆外,两个点到圆心距离相等,求圆上点到两个点距离和的最小值。

思路 : 首先要了解反演点

一般指二维反演中的点。
二维上反演以一个特定的反演圆为基础:圆心O为反演中心,圆半径为常数k,把点P反演为点P'就是使得OP×OP'=r^2 (来自百度百科)
首先做出两个点的反演点 P' 和 Q' ,ODP与ODP' 是相似三角型(这个不难证明)

所以极小的 PD + QD 可转化为极小的P'D + Q'D 

当P'Q'与圆有交点的时候可以使P'DQ'在同一直线上,这时P'Q'之间的距离就是 ODP' + ODQ'的最小值,那么ODP + ODQ的最小值就等于 P'Q' * (相似的比例)

当P'Q与圆无交点的时候,可以把P' 和 Q'当作一个椭圆的两个交点,我们知道椭圆上的点到椭圆上任意一点的距离之和都相等,所以我们慢慢放大椭圆直到与圆相切的时候,那个点就是最短距离点,你会发现,那个点一定在中垂线上,所以就去求中垂线与圆的交点的距离就可以了

#include<stdio.h>
#include<math.h>
#define eps 1e-8  

int main(){
	int T;
	double r,x1,y1,x2,y2,x3,y3,x4,y4;
	double d1,d2,d,k1,k2,dist,ans;
	double mx,my,smx,smy;
	scanf("%d",&T);
	while(T--){
		scanf("%lf %lf %lf %lf %lf",&r,&x1,&y1,&x2,&y2);
		
		d1 = sqrt(pow(x1,2) + pow(y1,2)); // 计算出其中一点到圆心距离 
		k1 = pow(r,2) / pow(d1,2);		// 这个 k 由 d(反演点) * d(p点) = r ^ 2 推出 
		x3 = x1 * k1,y3 = y1 * k1;		//用这个比例得出反演点坐标 
		x4 = x2 * k1,y4 = y2 * k1;
		
		mx = (x3 + x4) / 2;				//求出两反演点的中点 
		my = (y3 + y4) / 2;
		d2 = sqrt(pow(mx,2) + pow(my,2)); //中点到圆心的距离可以判断是否与圆相交 
		
		if(fabs(d1) <= eps){
			ans = 2 * r;
		}else if(d2 <= r){
			dist = sqrt(pow(x3 - x4,2) + pow(y3 - y4,2));
			k2 = d1 / r;
			ans = dist * k2;
		}else if(d2 > r){
			k2 = r / d2;
			smx = mx * k2,smy = my * k2;
			ans = 2 * (sqrt(pow(smx - x1,2) + pow(smy - y1,2)));
		}
		printf("%.7f\n",ans);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值