2019 acm icpc西安邀請賽 C Angel's Journey

Angel's Journey 

  •  24.64%
  •  1000ms
  •  262144K

“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,ry−r).

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(1≤T≤500) 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)(−102≤rx,ry,x,y≤102,0<r≤102).

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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double pi=acos(-1.0);
const double eps=1e-8;
double rx,ry,r,x,y;
double dis(double x1,double y1,double x2,double y2)
{
	return (double)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
	int t;scanf("%d",&t);
	while(t--)
	{
		cin>>rx>>ry>>r>>x>>y;
		double a=dis(rx,ry,x,y);
		double b=dis(rx,ry-r,x,y);
		double jiao1=acos((a+r*r-b)/(2.0*sqrt(a)*r));
		double jiao2=jiao1-acos(r/sqrt(a));
		if(jiao2<=(pi/2+eps))   //切點在下面
		{
			double ans;
			if(x<rx) ans=dis(rx-r,ry,x,y);
			else ans=dis(rx+r,ry,x,y);
			printf("%.4lf\n",sqrt(ans)+pi*r/2.0);
		}
		else printf("%.4lf\n",sqrt(a-r*r)+jiao2*r);
	}
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章