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,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

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

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

代码:

 //C-简单的计算几何
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+;
const double PI=acos(-1.0); int main()
{
int t;
scanf("%d",&t);
while(t--){
double rx,ry,r,x,y;
scanf("%lf%lf%lf%lf%lf",&rx,&ry,&r,&x,&y);
double length=0.0;
if((x<=rx-r)||(x>=rx+r)){
if(x<=rx-r){
length+=sqrt((x-(rx-r))*(x-(rx-r))+(y-ry)*(y-ry));
length+=0.5*PI*r;
}
else{
length+=sqrt((x-(rx+r))*(x-(rx+r))+(y-ry)*(y-ry));
length+=0.5*PI*r;
}
}
else{
double d=sqrt((x-rx)*(x-rx)+(y-ry)*(y-ry));
double jiao;
if(x!=rx){
double cosr=abs(x-rx)/d;
jiao=acos(cosr)-acos(r/d);
}
else{
jiao=0.5*PI-acos(r/d);
}
jiao+=0.5*PI;
length+=jiao*r;
length+=sqrt(d*d-r*r);
}
printf("%.4f\n",length);
}
}

计蒜客 39270.Angel's Journey-简单的计算几何 ((The 2019 ACM-ICPC China Shannxi Provincial Programming Contest C.) 2019ICPC西安邀请赛现场赛重现赛的更多相关文章

  1. 计蒜客 39280.Travel-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest M.) 2019ICPC西安邀请赛现场赛重现赛

    Travel There are nn planets in the MOT galaxy, and each planet has a unique number from 1 \sim n1∼n. ...

  2. 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛

    Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...

  3. 计蒜客 39272.Tree-树链剖分(点权)+带修改区间异或和 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest E.) 2019ICPC西安邀请赛现场赛重现赛

    Tree Ming and Hong are playing a simple game called nim game. They have nn piles of stones numbered  ...

  4. 计蒜客 39268.Tasks-签到 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest A.) 2019ICPC西安邀请赛现场赛重现赛

    Tasks It's too late now, but you still have too much work to do. There are nn tasks on your list. Th ...

  5. 计蒜客-跳跃游戏二 (简单dp)

    题目链接:https://nanti.jisuanke.com/t/20                                         跳跃游戏二 给定一个非负整数数组,假定你的初始 ...

  6. 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)

    query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...

  7. 计蒜客 31434 - 广场车神 - [DP+前缀和]

    题目链接:https://nanti.jisuanke.com/t/31434 小 D 是一位著名的车手,他热衷于在广场上飙车.每年儿童节过后,小 D 都会在广场上举行一场别样的车技大赛. 小 D 所 ...

  8. 2019计蒜客信息学提高组赛前膜你赛 #2(TooYoung,TooSimple,Sometimes Naive

    计蒜客\(2019CSP\)比赛第二场 巧妙爆零这场比赛(我连背包都不会了\(QWQ\) \(T1\) \(Too\) \(Young\) 大学选课真的是一件很苦恼的事呢! \(Marco\):&qu ...

  9. 计蒜客 作弊揭发者(string的应用)

    鉴于我市拥堵的交通状况,市政交管部门经过听证决定在道路两侧安置自动停车收费系统.当车辆驶入车位,系统会通过配有的摄像头拍摄车辆画面,通过识别车牌上的数字.字母序列识别车牌,通过连接车管所车辆信息数据库 ...

随机推荐

  1. 构建helm chart应用

    使用helm命令创建基础目录 helm create t2cp [root@node04 ~]# tree t2cp t2cp ├── charts ├── Chart.yaml ├── templa ...

  2. C#获取文件夹下的所有文件的方法

    目录 #基础知识 #只获取目录下一级的文件夹与文件 # 递归地输出当前运行程序所在的磁盘下的所有文件名和子目录名 正文   #基础知识 1.获得当前运行程序的路径 1 string rootPath ...

  3. Workerman简单开发示例实践(一)

    一.去官网下载workerman,地址:https://www.workerman.net/download,下载后解压任意文件夹. 二.在解压文件目录下新建http_test.php,输入如下代码: ...

  4. linux服务器管理常用命令

    1.ps命令 (Processes Status) ps这个命令是查看系统进程,ps 是显示瞬间行程的状态,并不动态连续. ==============ps 的参数说明================ ...

  5. Python_正则表达式语法

    1.正则表达式中的操作符: 2.re库的使用: import re #search方法要求只要待匹配的字符串中包含正则表达式中的字符串就可以 match = re.search('python+',' ...

  6. HTML&CSS基础-meta标签

    HTML&CSS基础-meta标签 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.常见字符集 1>ASCII 我们知道计算机是由外国人发明的,他们当时也没有考虑到 ...

  7. Hbase架构与原理(转)

    Hbase架构与原理 HBase是一个分布式的.面向列的开源数据库,该技术来源于 Fay Chang所撰写的Google论文“Bigtable:一个结构化数据的分布式存储系统”.就像Bigtable利 ...

  8. 将mysql从MyISAM更改为INNODB

    今天更新django中的表字段,由于mysql从5.1升级到5.7.以前的外键关联必须从MYISAM改新为INNODB才可以继续. 过程有点刺激,但还好,只要想清楚了过程,提前作好备份,就没啥大问题. ...

  9. Good Numbers(HDU5447+唯一分解)

    题目链接 传送门 题面 题意 首先定义对于\(k\)的好数\(u\):如果\(u\leq k\)且\(u\)的所有质因子与\(k\)的质因子一样则称\(u\)对于\(k\)是一个好数. 现给你两个数\ ...

  10. python学习之多窗口切换

    多窗口切换: from selenium import webdriver d = webdriver.Firefox() d.window_handles #显示所有的窗口 d.current_wi ...