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.
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
T≤500000
−100≤x,y≤100
1≤r≤100
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
T≤500000
−100≤x,y≤100
1≤r≤100
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 10−6 .
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if |a−b|max(1,b)≤10−6 .
The answer will be checked correct if its absolute or relative error doesn't exceed 10−6 .
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if |a−b|max(1,b)≤10−6 .
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;
}