题目链接

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
 
题意:有一个圆,圆心在原点,输入半径 r ,圆内有两个点P , Q 到圆心距离相同,现在求在圆上找一点M,使得PM+QM最小?
 
思路:
            
      对于圆内的两个点 P 和 Q ,如果以其作为椭圆两个焦点,由图一可以看到:当椭圆顶点与圆相切时 , 圆与椭圆会有三个焦点,而椭圆上的点到P、Q的距离和是定值。那么可以缩小椭圆,接下来会有四个交点,继续缩小椭圆,得到图二,椭圆与圆只有两个交点,因为椭圆外的点到两个焦点的距离和大于2a,而椭圆上的点到两个焦点的距离和为2a,。在图2中,除了两个交点外,其余圆上点均在椭圆外,所以这时的交点到P、Q两点的距离和最小,等于2a。
      如何找到这个相切的椭圆呢?二分解决。
      具体:由P、Q两个焦点,我们可以确定c=PQ/2 ,  现在如果再给出一个b值那么就能确定这个椭圆了,而b值越大椭圆越大,b值越小椭圆越小,所以我们要找到如图2所示,相切只有两个焦点时的b值,那么我们需要找的就是圆和椭圆相交时最小的b。我们可以求出图3中所示的 h 和 R -h ,那么椭圆的方程为:x^2/a^2 + (y-h)^2/b^2 = 1 ( 这个方程是PQ平行于X轴时的,但PQ不平行于X时也不影响,我们只是用它判断是否与圆相交 ) 圆:x^2 + y^2 =R^R ,    并且b>0(显然),b<R-h ,所以在(0,R-h) 二分查找b。
 
代码如下:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
const double eps = 1e-;
double dis(double x1,double y1,double x2,double y2 )
{
return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}
namespace IO {
const int MX = 4e7; //1e7占用内存11000kb
char buf[MX]; int c, sz;
void begin() {
c = ;
sz = fread(buf, , MX, stdin);
}
inline bool read(int &t) {
while(c < sz && buf[c] != '-' && (buf[c] < '' || buf[c] > '')) c++;
if(c >= sz) return false;
bool flag = ; if(buf[c] == '-') flag = , c++;
for(t = ; c < sz && '' <= buf[c] && buf[c] <= ''; c++) t = t * + buf[c] - '';
if(flag) t = -t;
return true;
}
} int main()
{
IO::begin();
int T;
double R,x1,x2,y1,y2;
double x3,y3;
double A,B,C,dt,ans1,ans2;
//cin>>T;
IO::read(T);
while(T--)
{
//scanf("%lf%lf%lf%lf%lf",&R,&x1,&y1,&x2,&y2);
int xr, xx1, xx2, yy1, yy2;
IO::read(xr);
IO::read(xx1);
IO::read(yy1);
IO::read(xx2);
IO::read(yy2);
R = xr;
x1 = xx1;y1 = yy1;x2 = xx2;y2 = yy2;
double c=dis(x1,y1,x2,y2)*0.5;
c=c*c;
x3=(x1+x2)*0.5;
y3=(y1+y2)*0.5;
double h=dis(x3,y3,0.0,0.0);
//cout<<h<<endl;
double Rb=R-h;
double Lb=0.0,b,a,mid; for(int i=; i<; i++)
{
mid=(Lb+Rb)*0.5;
b = mid;
b=b*b;
a=c+b;
A=a-b;
B=2.0*a*h;
C=b*R*R+a*h*h-a*b;
dt=B*B-4.0*A*C;
int flag=;
if(dt>=-eps)
{
ans1=(-B+sqrt(B*B-4.0*A*C))*0.5/A;
ans2=(-B-sqrt(B*B-4.0*A*C))*0.5/A;
ans1=ans1*ans1;
ans2=ans2*ans2;
if(R*R-ans1>=-eps||R*R-ans2>=-eps)
flag=;
}
if(flag==)
Rb=mid;
else
Lb=mid;
}
printf("%.10f\n",sqrt(a)*2.0); }
return ;
}

HDU 6097---Mindis(二分)的更多相关文章

  1. 2017多校第6场 HDU 6097 Mindis 计算几何,圆的反演

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6097 题意:有一个圆心在原点的圆,给定圆的半径,给定P.Q两点坐标(PO=QO,P.Q不在圆外),取圆 ...

  2. hdu 6097 Mindis(数学几何,圆心的反演点)

    Mindis Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  3. 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) , ...

  4. HDU 6097 Mindis (计算几何)

    题意:给一个圆C和圆心O,P.Q是圆上或圆内到圆心距离相等的两个点,在圆上取一点D,求|PD| + |QD|的最小值 析:首先这个题是可以用三分过的,不过也太,.... 官方题解: 很不幸不总是中垂线 ...

  5. UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)

    UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...

  6. hdu 2413(最大匹配+二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2413 思路:由于要求最少的时间,可以考虑二分,然后就是满足在limit时间下,如果地球战舰数目比外星战 ...

  7. HDU 5884 Sort (二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 nn个有序序列的归并排序.每次可以选择不超过kk个序列进行合并,合并代价为这些序列的长度和.总的 ...

  8. hdu 1281棋盘游戏(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281   Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...

  9. HDU 1025 DP + 二分

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1025 求最长递增子序列,O(n^2)的复杂度超时,需要优化为O(n*logn) f[i]存储长度为i的最小 ...

  10. hdu 2289 要二分的杯子

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2289 大意是 一个Cup,圆台形,给你它的顶部圆的半径,底部圆的半径,杯子的高度,和此时里面装的水的体 ...

随机推荐

  1. El表达式取map值

    map el表达取值 ${initMap['kehuList']}

  2. eclipse左侧的导航栏不见了怎么调

    点击eclipse上方导航栏的window 然后再点击Reset Perspective 这样左侧的导航栏就出来了

  3. php 函数形参前面加上&

    <?php function test(&$a){ $a=$a+100; } $b=1; echo $b;//输出1 test($b);//这里$b传递给函数的其实是$b的变量内容所处的 ...

  4. eclipse中Build Path 导入的包和复制到 lib 包的区别

    Java Build Path是我们编译需要的包,在比如在import ***.***.***时如果没用Java Build Path导入包的话类里面就有红叉,说不识别这个类,build path只是 ...

  5. template might not exist or might not be accessible by any of the configured Template Resolvers

    距离上一篇文章已经很长时间了,最近太忙碌了,今天发布spring boot遇到一个问题,找了好久才找到解决办法,今天贴出来和大家一起分享下,首先看错误信息 HTTP Status 500 - Requ ...

  6. 我的学习之路_第二十三章_HTML

    Html : 超级文本语言 ( Hyper text Markup Language ) HTML 文件扩展名是 * .html HTML 结构都是有标签组成 通常情况下标签有开始标签和结束标签组成 ...

  7. H5学习第二周

    怎么说,在各种感觉中h5学习的第二周已经过来了,先总结一下,感觉学习h5是一件让我爱恨交加的事,学会一些新的知识并把它成功运行出来的时候是非常激动和兴奋的,但是有时候搞不懂一个标签或者属性的时候,就有 ...

  8. C# 模拟跑马灯效果(2种)

    #region 跑马灯效果方法 /// <summary> /// 文字进入左侧后从右侧出来 /// </summary> private void LabelRun() { ...

  9. CSS自适应的占位符效果

    一种不错的自适应input效果,分享一下.html section : <div style="width:500px;height:500px;margin:300px auto;b ...

  10. accp8.0转换教材第5章事务、视图、索引、备份和恢复理解与练习

    知识点:事务.视图.索引.数据库的备份和恢复 一.单词部分 ①transation事务②atomicity原子性③consistency一致性④isolation隔离性 ⑤durability持久性⑥ ...