题目大意:
给你两个点,代表拔河的两只队伍的位置。有这样一个柱子,以原点为圆心,r为半径。那么拔河两只队伍拉的绳子很可能绕到柱子上,给你两个队伍的位置以及圆柱的半径,求拔河用绳子的最短长度。
分析:
注意两点在圆外。
#include <iostream>
#include <cstdio>
#include <cmath>
#define eps 1e-9
using namespace std;
int main()
{
int N;
double x1,x2,y1,y2,e2,f2,g2,r,A,ans;
scanf("%d",&N);
while(N--)
{
scanf("%lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&r);
e2 = (x1-x2)*(x1-x2) +(y1-y2)*(y1-y2);
f2 = x1*x1 + y1*y1;
g2 = x2*x2 + y2*y2;
A = fabs(acos((x1*x2+y2*y1)/sqrt(f2*g2))) - acos(r/sqrt(f2)) - acos(r/sqrt(g2));
//printf("A = %lf\n",A);
if(A>-eps) ans = A*r + sqrt(f2 - r*r) + sqrt(g2 - r*r);
else
ans = sqrt(e2);
printf("%.3lf\n",ans);
}
return 0;
}