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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值