Hdu6097 Mindis(2017多校第6场)

来源:互联网 发布:linux iptables pat 编辑:程序博客网 时间:2024/05/21 11:04

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
444 00 440 33 040 22 040 11 0
 

Sample Output
5.65685435.65685435.89450306.7359174
 

Source
2017 Multi-University Training Contest - Team 6

————————————————————————————————
题目的意思是给出一个圆,和圆内(上)距圆心的相等的两个点,求在圆上取一个点使得到这两个点的距离和最小
思路:数学推导出公式计算,注意卡精度(队友真是太强了)
#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;}
原创粉丝点击