Problem B: Battle Royale(简单几何)

 题目链接:

B - Battle Royale

 Gym - 102021B 

题目大意:给你两个坐标,表示起点和终点,然后给你两个圆,第一个圆包含两个圆,然后问你起点到终点的最短距离(不经过第二个圆)。

具体思路:首先求出第一个点到圆的切点之间的距离,然后求出第二个点到圆的切点之间的距离,再加上那一段圆弧的长度,就是最短距离。

这个题弧度转换成角度的话,会损失精度,可以直接利用弧度进行计算,弧度计算长度,(角度/(2*pi))*2*pi*r.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 # define ll long long
 4 # define inf 0x3f3f3f3f
 5 const double pi = acos(-1.0);
 6 const int maxn = 2e6+100;
 7 double dis(double x1,double y1,double x2,double y2)
 8 {
 9     return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
10 }
11 int main()
12 {
13     double  xc,yc;
14     double  xd,yd,xb,yb,rb,xr,yr,rr;
15     scanf("%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",&xc,&yc,&xd,&yd,&xb,&yb,&rb,&xr,&yr,&rr);
16     double l1=dis(xc,yc,xr,yr),l2=dis(xd,yd,xr,yr),l3=dis(xc,yc,xd,yd);
17     double o1=acos(rr/l1);
18     double o2=acos(rr/l2);
19     double tmp=acos((l1*l1+l2*l2-l3*l3)/(2.0*l1*l2));
20     double s=((tmp-o1-o2))*rr;
21     double ans=sqrt(l1*l1-rr*rr)+sqrt(l2*l2-rr*rr)+s;
22    cout<<fixed<<setprecision(8)<<ans<<endl;
23     return 0;
24 }

 

posted @ 2019-04-22 14:38  Let_Life_Stop  阅读(275)  评论(0编辑  收藏  举报