Total passenger garlic 39270.Angel's Journey- simple computational geometry ((The 2019 ACM-ICPC China Shannxi Provincial Programming Contest C.) 2019ICPC Xi'an Invitational tournament site game to reproduce

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).

Sample input

2
1 1 1 2 2 
1 1 1 1 3

Sample Output

2.5708
3.8264

 

 

Meaning of the questions is to give a round, seek from the bottom of the circle, the shortest distance from the outer circle a circle above the midline position.

The game, the board sets crooked, hand calculations can be found directly.

 

Code:

. 1  // the C-simple geometric calculations 
2 #include <bits / STDC ++ H.>
 . 3  the using  namespace STD;
 . 4 typedef Long  Long LL;
 . 5  const  int MAXN 1E5 + = 10 ;
 . 6  const  Double the PI = ACOS (- 1.0 );
 . 7  
. 8  int main ()
 . 9  {
 10      int T;
 . 11      Scanf ( " % D " , & T);
 12 is      the while (T-- ) {
 13 is          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\n",length);
41     }
42 }

 

Guess you like

Origin www.cnblogs.com/ZERO-/p/11283278.html