HDU 6097 Mindis 几何

来源:互联网 发布:法修史丹比特 知乎 编辑:程序博客网 时间:2024/06/07 08:36

题目链接:HDU 6097

Mindis

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3168    Accepted Submission(s): 644
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
 
题意:
一个圆和2个点PQ,PQ在园内并且OP=OQ,然后找圆上一点D使得PD+QD最小。
题目分析:
找PQ的反演点然后巧妙的构造相似三角形,很巧妙的解决了精度和时间问题。给“优秀的黄金分割”卡过的dalao们递茶~

////  main.cpp//  HDU6097 Mindis////  Created by teddywang on 2017/8/13.//  Copyright © 2017年 teddywang. All rights reserved.//#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;double xp,yp,xq,yq,r,R;double x,y,x2,y2;double eps=1e-8;int T;struct point{    double x,y;    point(){        x=0;        y=0;    }    point(double X,double Y){        x=X;        y=Y;    }    };point p,q;point zero=point(0.0,0.0);double dis(point a,point b){    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}point shucheng(point a,double b){    point c=point(a.x*b,a.y*b);    return c;}double chacheng(point a,point b){    double buf=(a.x*b.y)-(a.y*b.x);    if(buf>eps) return buf;    else return 0-buf;}bool judge_eq(point a,point b){    if(a.x==b.x&&a.y==b.y) return true;    else return false;}bool judge2(point a,point b){    double buf=r*r/dis(zero,a)/dis(zero,b);    point c=shucheng(a,buf);    point d=shucheng(b,buf);    double s=chacheng(c,d)/dis(c,d);    if(s-r>eps) return false;    else return true;}int main(){    scanf("%d",&T);    double ans;    while(T--)    {        scanf("%lf",&r);        scanf("%lf%lf",&p.x,&p.y);        scanf("%lf%lf",&q.x,&q.y);        if(judge_eq(p, q))        {            ans=(r-dis(zero,p))*2;        }        else        {            if(judge2(p,q))            {                double buf=r*r/dis(zero,p)/dis(zero,p);                point p1=shucheng(p,buf);                point q1=shucheng(q,buf);                ans=dis(p1,q1)*dis(p,zero)/r;            }            else            {                point mid=point((p.x+q.x)/2.00,(p.y+q.y)/2.00);                double buf=r/dis(zero,mid);                mid=shucheng(mid,buf);                ans=dis(mid,p)+dis(mid,q);            }        }        printf("%.7f\n",ans);    }}


原创粉丝点击