HDU 6097---Mindis(二分)
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.
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
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.


#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(二分)的更多相关文章
- 2017多校第6场 HDU 6097 Mindis 计算几何,圆的反演
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6097 题意:有一个圆心在原点的圆,给定圆的半径,给定P.Q两点坐标(PO=QO,P.Q不在圆外),取圆 ...
- hdu 6097 Mindis(数学几何,圆心的反演点)
Mindis Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- 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) , ...
- HDU 6097 Mindis (计算几何)
题意:给一个圆C和圆心O,P.Q是圆上或圆内到圆心距离相等的两个点,在圆上取一点D,求|PD| + |QD|的最小值 析:首先这个题是可以用三分过的,不过也太,.... 官方题解: 很不幸不总是中垂线 ...
- UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)
UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...
- hdu 2413(最大匹配+二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2413 思路:由于要求最少的时间,可以考虑二分,然后就是满足在limit时间下,如果地球战舰数目比外星战 ...
- HDU 5884 Sort (二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 nn个有序序列的归并排序.每次可以选择不超过kk个序列进行合并,合并代价为这些序列的长度和.总的 ...
- hdu 1281棋盘游戏(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...
- HDU 1025 DP + 二分
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1025 求最长递增子序列,O(n^2)的复杂度超时,需要优化为O(n*logn) f[i]存储长度为i的最小 ...
- hdu 2289 要二分的杯子
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2289 大意是 一个Cup,圆台形,给你它的顶部圆的半径,底部圆的半径,杯子的高度,和此时里面装的水的体 ...
随机推荐
- mysql安装不上 failed to install the service
先前安装的没有卸载干净必须删除相应的注册表方法如下:1)“运行”中敲入“Regedit”进入注册表编辑2)HKEY_LOCAL_MACHINE->SYSTEM->ControlSet001 ...
- [leetcode-485-Max Consecutive Ones]
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
- NewsDao
package com.pb.news.dao; import java.util.Date;import java.util.List; import com.pb.news.entity.News ...
- jquery中append与appendTo方法区别
1. append(content)方法 方法作用:向每个匹配的元素内部追加内容. 参数介绍:content (<Content>): 要追加到目标中的内容. 用法示例: HTML代码为& ...
- Wince 创新布局
如果你的项目是用wince开发并且机器是小型的pda,你可以考虑有这种布局方式. IDE上布局,如图 /// <summary> /// 显示层 /// </summary> ...
- [CF787D]遗产(Legacy)-线段树-优化Dijkstra(内含数据生成器)
Problem 遗产 题目大意 给出一个带权有向图,有三种操作: 1.u->v添加一条权值为w的边 2.区间[l,r]->v添加权值为w的边 3.v->区间[l,r]添加权值为w的边 ...
- multipath多路径实验01-构建iscsi模拟环境
multipath多路径实验01-构建iscsi模拟环境 前几天跟同事网上闲聊技术,吐槽之前自己没有配置过多路径的经历,虽然多路径的配置过程很简单,职责划分也应是主机或存储工程师来搞定,DBA只需要直 ...
- JS操作数组常用的方法
JS操作Array对象的方法 concat(arr1,arr2,...):连接数组indexOf(value):返回数组中value的第一个索引join(separator):将数组中所有的元素连接由 ...
- Java并发编程笔记——技术点汇总
目录 · 线程安全 · 线程安全的实现方法 · 互斥同步 · 非阻塞同步 · 无同步 · volatile关键字 · 线程间通信 · Object.wait()方法 · Object.notify() ...
- linux和Windows实现文件共享之samba的安装与配置
背景: 项目需求linux的一个目录,需要在两台windows目录上面进行同时共享. 使用mount时发现,通过mount将同一个linux上面的目录挂载在两台windows机器上时,会出现文件隐藏的 ...