Hdu6097 Mindis(2017多校第6场)

Mindis

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

————————————————————————————————
题目的意思是给出一个圆,和圆内(上)距圆心的相等的两个点,求在圆上取一个点使得到这两个点的距离和最小
思路:数学推导出公式计算,注意卡精度(队友真是太强了)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <functional>

using namespace std;

int R;
int x[3],y[3];

double ddabs(double xx)
{
    if(xx < 0) return -xx;
    return xx;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&R);
        for(int i=1;i<=2;i++) scanf("%d%d",&x[i],&y[i]);
        int rr=(x[1]*x[1])+(y[1]*y[1]);
        if(rr == 0)
        {
            printf("%.7f\n", R * 2.0);
            continue;
        }
        int dd=(x[1]-x[2])*(x[1]-x[2])+(y[1]-y[2])*(y[1]-y[2]);
        double o=acos((2.0*rr-dd)/rr/2.0);
        double a,b,ans1;
        double r=sqrt(1.0 * rr);
        a=1.0*(R*R+rr)*cos(o/2.0)/(2.0*R*r);
        b=a*a-(1.0+(2.0*rr-dd)/rr/2.0)/2.0;
        if(ddabs(b) < 1e-8)
            b = 0;
        ans1=a+sqrt(b);
        double t;
        if(ans1 > 1 || ans1 < cos(o))
        {
            t = o/2.0;
        }
        else
        {
            t=acos(ans1)*2.0;
            t=(t+o)/2.0;
        }
        double x=sqrt(R*R+rr-2.0*R*r*cos(t));
        double y=sqrt(R*R+rr-2.0*R*r*cos(o-t));
        printf("%.7f\n",x+y);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值