HDU 6097 Mindis【几何】


Mindis

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2800    Accepted Submission(s): 563
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
 


思路:作P、Q的反演点,即 OPOP=r2OQOQ=r2 ,根据 PQ 与圆是否相交来判断D的位置,若相交则结果为 PQ 乘上比例 OP/r ,若不相交,则先求出 PQ 的中点 D ,在根据比例确定 D 的位置,计算 PD+QD 即可。


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
#define ll long long
#define ms(a,b)  memset(a,b,sizeof(a))
#define maxn 510
const int M=1e3+10;
const int MM=2e3+10;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;;
const double eps=1e-8;
struct node
{
    double x,y;
}p[10];

int dcmp(double x)
{
    if(fabs(x)<=eps)return 0;
    return x<0?-1:1;
}

double cal(double x1,double y1,double x2,double y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        double r;
        scanf("%lf",&r);
        scanf("%lf%lf",&p[1].x,&p[1].y);
        scanf("%lf%lf",&p[2].x,&p[2].y);
        double op=cal(p[1].x,p[1].y,0,0);
        if(dcmp(op)==0){
            printf("%.7f\n",2*r);
            continue;
        }
        double k=r*r/op/op;
        p[3].x=p[1].x*k;p[3].y=p[1].y*k;
        p[4].x=p[2].x*k;p[4].y=p[2].y*k;
        p[5].x=(p[3].x+p[4].x)/2;
        p[5].y=(p[4].y+p[3].y)/2;
        double od=cal(p[5].x,p[5].y,0,0);
        if(od<=r){
            printf("%.7f\n",cal(p[3].x,p[3].y,p[4].x,p[4].y)*op/r);
        }
        else {
            p[6].x=p[5].x*r/od;p[6].y=p[5].y*r/od;
            printf("%.7f\n",2*cal(p[6].x,p[6].y,p[1].x,p[1].y));
        }
    }
    return 0;
}


Mindis

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2800    Accepted Submission(s): 563
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
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值