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

最新文章

  1. 迷你MVVM框架 avalonjs 实现上的几个难点
  2. 批处理——服务器的web文件备份
  3. 手机客户端UI测试常见的测试点
  4. SVN分支研究
  5. 【BZOJ-3545&amp;3551】Peaks&amp;加强版 Kruskal重构树 + 主席树 + DFS序 + 倍增
  6. 李洪强iOS开发之OC[012] -类的声明实现小结
  7. ReactiveSwift源码解析(九) SignalProducerProtocol延展中的Start、Lift系列方法的代码实现
  8. JavaScript Dom入门
  9. Flutter 即学即用系列博客——01 环境搭建
  10. python爬虫之scrapy安装(一)
  11. HDFS笔记(二)
  12. piwik获取访客头像,自定义显示访问者头像(URL)和描述(标题和替代)
  13. MMCM与PLL
  14. Xcode debug时如何查看内存中的数据
  15. myisam innodb 次级 索引的区别
  16. hdfs的java接口简单示例
  17. 用vue实现省市县三级联动
  18. 使用oVal进行Java Bean 验证的注意事项
  19. AC-PC线(前联合-后联合线)
  20. bean对grub4dos做出的巨大贡献总结

热门文章

  1. IntelliJ IDEA 换背景免费酷炫的插件(转)
  2. 【C#】 获取计算机的硬件信息
  3. IE浏览器 location.href 不跳转
  4. 浅谈有趣的 //go: 指令
  5. Docker/Dockerfile debug调试技巧
  6. 关于.Net使用企业库访问MySql数据库
  7. Spring Boot后端与Angular前端进行timestamp的交互
  8. 获取本机的IP地址和mac地址
  9. 【面试突击】-RabbitMQ常见面试题(二)
  10. Linux下which、whereis、locate、find命令作用