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 }
  • 相关阅读:
    HDU 1058 Humble Numbers
    HDU 1160 FatMouse's Speed
    HDU 1087 Super Jumping! Jumping! Jumping!
    HDU 1003 Max Sum
    HDU 1297 Children’s Queue
    UVA1584环状序列 Circular Sequence
    UVA442 矩阵链乘 Matrix Chain Multiplication
    DjangoModels修改后出现You are trying to add a non-nullable field 'download' to book without a default; we can't do that (the database needs something to populate existing rows). Please select a fix:
    opencv做的简单播放器
    c++文件流输入输出
  • 原文地址:https://www.cnblogs.com/acvc/p/4303962.html
Copyright © 2011-2022 走看看