zoukankan      html  css  js  c++  java
  • C

     1 #include <cstdio>
     2 #include <cstdlib>
     3 #include <cmath>
     4 
     5 const double pi = acos(-1);
     6 struct point{
     7     double x,y;
     8 }L,R,O;
     9 double r;
    10 
    11 double dis(const struct point &a,const struct point &b){
    12     return sqrt( (a.x - b.x)*(a.x - b.x) + (a.y-b.y)*(a.y-b.y) );
    13 }
    14 double D_dis(const struct point &a,const struct point &b){
    15     return (a.x - b.x)*(a.x - b.x) + (a.y-b.y)*(a.y-b.y) ;
    16 }
    17 double getArea(const point &x, const point &y, const point & z){
    18     double a = dis(x,y);
    19     double b = dis(y,z);
    20     double c = dis(z,x);
    21     double p = (a+b+c)/2;
    22     return sqrt(p*(p-a)*(p-b)*(p-c)) * 2;
    23 }
    24 int main(){
    25  //   freopen("1.in","r",stdin);
    26  //   freopen("1.out","w",stdout);
    27  //freopen("1.txt","w",stdout);
    28     int CASE;
    29     scanf("%d",&CASE);
    30     while(CASE--){
    31         scanf("%lf %lf %lf",&O.x,&O.y,&r);
    32         scanf("%lf %lf",&L.x,&L.y);
    33         scanf("%lf %lf",&R.x,&R.y);
    34         if( dis(O,L) < r && dis(O,R) < r ){
    35             printf("%.3lf ",dis(L,R));
    36         }else if( dis(O,L) < r || dis(O,R) < r ){
    37             printf("Impossible! ");
    38         }else{
    39             if ( getArea(L,R,O) / dis(L,R) < r ){
    40                 if (D_dis(L,O)+D_dis(L,R)<D_dis(R,O)||D_dis(R,O)+D_dis(L,R)<D_dis(L,O))  {
    41                     printf("%.3lf ",dis(L,R));
    42 
    43                 }
    44                 else {
    45                 double ans = sqrt(D_dis(L,O) - r*r) + sqrt(D_dis(R,O) - r*r);
    46                 double rads = acos( (D_dis(L,O) + D_dis(R,O) - D_dis(L,R) ) / (2*dis(L,O)*dis(R,O) ) );
    47                 //printf("rads = %lf ",rads);
    48                 double left_rads = rads - acos(r / dis(L,O)) - acos(r / dis(R,O) );
    49                 ans += left_rads * r;
    50                 printf("%.3lf ",ans);
    51                 }
    52             }else{
    53                 printf("%.3lf ",dis(L,R));
    54             }
    55         }
    56     }
    57     return 0;
    58 }
  • 相关阅读:
    爬取网易云音乐歌手和id
    【兼容调试】cffi library '_openssl' has no function, constant or global variable named 'Cryptography_HAS
    python如何去掉字符串‘xa0’
    python 中json和字符串互相转换
    vip视频播放
    一行Python代码画心型
    Java语言编写MD5加密方法,Jmeter如何给字符串MD5加密
    转载:oracle RAC集群启动和关闭
    转载:oracle 11g ADG实施手册(亲测,已成功部署多次)
    如何上传本地文件到github又如何删除自己的github仓库
  • 原文地址:https://www.cnblogs.com/acvc/p/4303962.html
Copyright © 2011-2022 走看看