zoukankan      html  css  js  c++  java
  • 计蒜客 39270.Angel's Journey-简单的计算几何 ((The 2019 ACM-ICPC China Shannxi Provincial Programming Contest C.) 2019ICPC西安邀请赛现场赛重现赛

    Angel's Journey

    “Miyane!” This day Hana asks Miyako for help again. Hana plays the part of angel on the stage show of the cultural festival, and she is going to look for her human friend, Hinata. So she must find the shortest path to Hinata’s house.

    The area where angels live is a circle, and Hana lives at the bottom of this circle. That means if the coordinates of circle’s center is (rx, ry)(rx,ry) and its radius is rr, Hana will live at (rx, ry - r)(rx,ryr).

    Apparently, there are many difficulties in this journey. The area which is located both outside the circle and below the line y = ryy=ry is the sea, so Hana cannot pass this area. And the area inside the circle is the holy land of angels, Hana cannot pass this area neither.

    However, Miyako cannot calculate the length of the shortest path either. For the loveliest Hana in the world, please help her solve this problem!

    Input

    Each test file contains several test cases. In each test file:

    The first line contains a single integer T(1 le T le 500)T(1T500) which is the number of test cases.

    Each test case contains only one line with five integers: the coordinates of center rxrx 、 ryry, the radius rr, thecoordinates of Hinata’s house xx 、yy. The test data guarantees that y > ryy>ry and (x, y)(x,y) is out of the circle. (-10^2 le rx,ry,x,y le 10^2,0 < r le 10^2)(102rx,ry,x,y102,0<r102).

    Output

    For each test case, you should print one line with your answer (please keep 44 decimal places).

    样例输入

    2
    1 1 1 2 2 
    1 1 1 1 3

    样例输出

    2.5708
    3.8264

    题意就是给一个圆,求从圆的最底下,到圆中线上面的圆外一个位置的最短距离。

    比赛时,板子套歪了,发现直接手算就可以。

    代码:

     1 //C-简单的计算几何
     2 #include<bits/stdc++.h>
     3 using namespace std;
     4 typedef long long ll;
     5 const int maxn=1e5+10;
     6 const double PI=acos(-1.0);
     7 
     8 int main()
     9 {
    10     int t;
    11     scanf("%d",&t);
    12     while(t--){
    13         double rx,ry,r,x,y;
    14         scanf("%lf%lf%lf%lf%lf",&rx,&ry,&r,&x,&y);
    15         double length=0.0;
    16         if((x<=rx-r)||(x>=rx+r)){
    17             if(x<=rx-r){
    18                 length+=sqrt((x-(rx-r))*(x-(rx-r))+(y-ry)*(y-ry));
    19                 length+=0.5*PI*r;
    20             }
    21             else{
    22                 length+=sqrt((x-(rx+r))*(x-(rx+r))+(y-ry)*(y-ry));
    23                 length+=0.5*PI*r;
    24             }
    25         }
    26         else{
    27             double d=sqrt((x-rx)*(x-rx)+(y-ry)*(y-ry));
    28             double jiao;
    29             if(x!=rx){
    30                 double cosr=abs(x-rx)/d;
    31                 jiao=acos(cosr)-acos(r/d);
    32             }
    33             else{
    34                 jiao=0.5*PI-acos(r/d);
    35             }
    36             jiao+=0.5*PI;
    37             length+=jiao*r;
    38             length+=sqrt(d*d-r*r);
    39         }
    40         printf("%.4f
    ",length);
    41     }
    42 }
  • 相关阅读:
    性能测试七:jmeter进阶之文件上传下载、定时器
    性能测试六:jmeter进阶之Cookie与header管理器
    导出文本、表格、图像到PDF格式文件中(学习整理)
    数据库(学习整理)----7--Oracle多表查询,三种join连接
    反射(学习整理)----Class类和加载器ClassLoader类的整理
    反射(学习整理)----操作类、属性、方法!
    数据库(学习整理)----6--Oracle如何快速备份和多次备份数表数据
    数据库(学习整理)----5--Oracle常用的组函数
    数据库(学习整理)----4--Oracle数据查询(基础点1)
    Java小例子(学习整理)-----学生管理系统-控制台版
  • 原文地址:https://www.cnblogs.com/ZERO-/p/11283278.html
Copyright © 2011-2022 走看看