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
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.
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
2017 Multi-University Training Contest - Team 6
Recommend
liuyiding | We have carefully selected several similar problems for you: 6119 6118 6117 6116 6115
给一个圆及其半径R和圆上的两个点P、Q,在圆上找一个点D使得PD+QD的值最小,并输出。
哈,是不是发现初中做过这种数学题! 那就愉快的解决吧!
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
// 不要小瞧人生啊
const double eps = 1e-8;
struct node
{
double x, y;
}p[10];
int check(double x)
{
if (fabs(x) <= eps) return 0;//保證精確度
return x<0 ? -1 : 1;
}
double sen(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 = sen(p[1].x, p[1].y, 0, 0);
if (check(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[3].y + p[4].y) / 2;
double od = sen(p[5].x, p[5].y, 0, 0);
if (od <= r)
{
printf("%.7f\n", sen(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 * sen(p[6].x, p[6].y, p[1].x, p[1].y));
}
}
return 0;
}