2017ACM暑期多校联合训练 - Team 6 1002 HDU 6097 Mindis (数学)
Problem Description
The center coordinate of the circle C is O, the coordinate of O is (0,0) , and the radius is r.
P and Q are two points not outside the circle, and PO = QO.
You need to find a point D on the circle, which makes PD+QD minimum.
Output minimum distance sum.
Input
The first line of the input gives the number of test cases T; T test cases follow.
Each case begins with one line with r : the radius of the circle C.
Next two line each line contains two integers x , y denotes the coordinate of P and Q.
Limits
T≤500000
−100≤x,y≤100
1≤r≤100
Output
For each case output one line denotes the answer.
The answer will be checked correct if its absolute or relative error doesn't exceed 10−6.
Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if |a−b|max(1,b)≤10−6.
Sample Input
4
4
4 0
0 4
4
0 3
3 0
4
0 2
2 0
4
0 1
1 0
Sample Output
5.6568543
5.6568543
5.8945030
6.7359174
题意:
给定一个圆心在坐标原点的圆以及该圆的半径,然后给出两个到该圆的圆心等长的非圆外点(点既可以在圆内,也可以在圆上),让从圆上找一点使其到两点的距离最短。
分析:
首先我们考虑两种最特殊的情况:
1.两个点共位置,这种情况也是完全满足题上给出的条件的,这样的话最短距离就是圆半径减去圆心到改点的距离,因为要看做两个点所以还得乘以2.
2.两个点在圆上,这样的话最短距离就是两点之间的距离。
考虑完这两种特殊的情况之后我么看一下一般的情况。
首先介绍一下反演点的定义:
如果圆内有一点P,过圆心做一条与P的连线,将这条线延长,使得在圆外的这条线上有一点P',与P关于该圆对称。
我们即可得出结论OP×OP'=r×r(r为该圆的半径)

然后我们就可以将求DP+DQ转换为求DP' +DQ',
现在的问题在于何种情况下这个点都是在中垂线上的这个点吗?
答案当然不是,我们通过连接两个反演点就可以发现,两个反演点的连线有可能与圆相交,相切的时候可以很简单的确定切点即为所求的点,相离也是如此,问题是相交的时候这个点应该如何确定呢?
相交的时候P、Q、P'、Q'可以构成一个等腰梯形,梯形与圆有一条腰的平分线,这条平分线就是我们要找的最短的距离,当然梯形与圆的交点不是我们要找的点,我们只是通过等量的转换将它转换过来而已。
后面在求DP'的长度的时候,应用到一些有关椭圆的知识,P’Q'就是椭圆的长轴,D到椭圆中心的连线即为短半轴,这样的话DP’即为c,可以简单的求得,最终求出答案。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;
const double esp=0.000000005;
double dis(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
double r,x[2],y[2];
scanf("%lf%lf%lf%lf%lf",&r,&x[0],&y[0],&x[1],&y[1]);
double op=dis(0.0,0.0,x[0],y[0]);
if(x[0]==x[1]&&y[0]==y[1])
{
printf("%.7lf\n",2.0*(r-op));
continue;
}
if(op==r)
{
printf("%.7lf\n",dis(x[0],y[0],x[1],y[1]));
continue;
}
double o=acos((x[0]*x[1]+y[0]*y[1])/op/op)/2.0;///op与od的夹角
double d=r*r/op;///d表示的是圆心到反演点的距离
double h=d*cos(o);/// 两反演点构成的直线的距离
if(h<=r)
{
printf("%.7lf\n",2.0*r*sin(o));
continue;
}
double b=h-r,a=d*sin(o);
printf("%.7lf\n",op*sqrt(a*a+b*b)*2.0/r);
}
return 0;
}
2017ACM暑期多校联合训练 - Team 6 1002 HDU 6097 Mindis (数学)的更多相关文章
- 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)
题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...
- 2017ACM暑期多校联合训练 - Team 7 1002 HDU 6121 Build a tree (深搜+思维)
题目链接 Problem Description HazelFan wants to build a rooted tree. The tree has n nodes labeled 0 to n− ...
- 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)
题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...
- 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)
题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...
- 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)
题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...
- 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)
题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...
- 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)
题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...
- 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)
题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...
- 2017ACM暑期多校联合训练 - Team 8 1008 HDU 6140 Hybrid Crystals (模拟)
题目链接 Problem Description Kyber crystals, also called the living crystal or simply the kyber, and kno ...
随机推荐
- Binlog的三种模式
binlog模式分三种(row,statement,mixed) 1.Row 日志中会记录成每一行数据被修改的形式,然后在slave端再对相同的数据进行修改,只记录要修改的数据,只有value,不会有 ...
- Git回滚merge操作
执行完merge操作后,没有修改代码 1.命令 ⑴ git reflog 查看merge操作的上一个提交记录的版本号 ⑵ git reset –hard 版本号 这样可以回滚到merge之前的状态 2 ...
- spring学习12 -Spring 框架模块以及面试常见问题注解等
以下为spring常见面试问题: 1.Spring 框架中都用到了哪些设计模式? Spring框架中使用到了大量的设计模式,下面列举了比较有代表性的: 代理模式—在AOP和remoting中被用的比较 ...
- CSS自适应导航菜单
以下是一个简单实例,可以通过学习了解响应工菜单的制作. html <nav class="nav"> <ul> <li class="cur ...
- HDU 3579——Hello Kiki
好久没写什么数论,同余之类的东西了. 昨天第一次用了剩余定理解题,今天上百度搜了一下hdu中国剩余定理.于是就发现了这个题目. 题目的意思很简单.就是告诉你n个m[i],和n个a[i].表示一个数对m ...
- 集成学习—boosting和bagging异同
集成学习 集成学习通过构建并结合多个学习器来完成学习任务.只包含同种类型的个体学习器,这样的集成是“同质”的:包含不同类型的个体学习器,这样的集成是“异质”的.集成学习通过将多个学习器进行结合,常可获 ...
- BZOJ3884 上帝与集合的正确用法(欧拉函数)
设f(n)为模n时的答案,由2k mod n=2k mod φ(n)+φ(n) mod n(并不会证),且k mod φ(n)=f(φ(n)),直接就可以得到一个递推式子.记搜一发即可. #inclu ...
- 吉哥系列故事――完美队形II HDU - 4513(马拉车变一下形)
题意: 求最长回文串...但这个回文串要符合从中间到两头 逐个递减 解析: 在扩散的时候加一个判断就好了 #include <iostream> #include <cstdio&g ...
- jQuery高度及位置操作
1. 获取滑轮位置,scrolltop:上下滚动的意思. <!DOCTYPE html> <html lang="en"> <head> < ...
- [NOIP2016 D1T3]换教室 【floyd+概率dp】
题目描述 对于刚上大学的牛牛来说,他面临的第一个问题是如何根据实际情况申请合适的课程. 在可以选择的课程中,有 2n2n 节课程安排在 nn 个时间段上.在第 ii(1 \leq i \leq n1≤ ...