zoukankan      html  css  js  c++  java
  • 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 }

     

  • 相关阅读:
    第二天续
    使用git提交本地仓库每次需要输入账号密码的问题解决
    第二天
    开启远程之路
    第一天
    第一步了解并且安装配置
    6
    Algorithms
    Algorithms
    Algorithms
  • 原文地址:https://www.cnblogs.com/letlifestop/p/10749993.html
Copyright © 2011-2022 走看看