HDU 6097 Mindis

来源:互联网 发布:php修复00截断的版本 编辑:程序博客网 时间:2024/06/05 23:25

Mindis

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1525    Accepted Submission(s): 239
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
444 00 440 33 040 22 040 11 0
 

Sample Output
5.65685435.65685435.89450306.7359174
 

Source
2017 Multi-University Training Contest - Team 6

题意:
在平面直角坐标系中,一个圆的圆心在原点
在该圆上或圆内给出两点P,Q,使得两点到圆心距离相等 PO = QO
现在,在圆上找出一点D,使得PD+QD的值最小

题解:
做P,Q反演点P',Q'
连接P'Q',做中垂线
(以P‘Q’为焦点做椭圆,存在椭圆的几何性质,椭圆上任一点到两焦点之和距离相等)
中垂线与圆的交点即为所求D点
再根据相似三角形的几何性质,求出比例关系 对应相乘即可
(思路参考kkkkahlua 谢谢哥)



#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>#define ll long longusing namespace std;const double eps = 1e-8;int main(){int t;scanf("%d",&t);while(t--){double r,x1,y1,x2,y2,ans;scanf("%lf %lf %lf %lf %lf",&r,&x1,&y1,&x2,&y2);double d0 = sqrt(x1 * x1 + y1 * y1);if(fabs(d0) < eps){printf("%.7lf\n",2 * r);continue;}//利用相似三角形比例关系证明 double k = r * r / (d0 * d0);double px = x1 * k,py = y1 * k;double qx = x2 * k,qy = y2 * k;double midx = (px + qx) / 2;double midy = (py + qy) / 2;double d = sqrt(midx * midx + midy * midy);if(d <= r){//与圆有交点 利用P’Q’与O的距离和半径进行比较 double distance = sqrt(pow(px - qx,2) + pow(py - qy,2));ans = distance * d0 / r;}else{double sumx = midx * (r / d);double sumy = midy * (r / d);ans = 2 * sqrt(pow(sumx - x1,2) + pow(sumy - y1,2));}printf("%.7lf\n",ans);}return 0;}


原创粉丝点击