E - Nature Reserve CodeForces - 1059D
There is a forest that we model as a plane and live nn rare animals. Animal number iihas its lair in the point (xi,yi)(xi,yi). In order to protect them, a decision to build a nature reserve has been made.
The reserve must have a form of a circle containing all lairs. There is also a straight river flowing through the forest. All animals drink from this river, therefore it must have at least one common point with the reserve. On the other hand, ships constantly sail along the river, so the reserve must not have more than one common point with the river.
For convenience, scientists have made a transformation of coordinates so that the river is defined by y=0y=0. Check whether it is possible to build a reserve, and if possible, find the minimum possible radius of such a reserve.
Input
The first line contains one integer nn (1≤n≤1051≤n≤105) — the number of animals.
Each of the next nn lines contains two integers xixi, yiyi (−107≤xi,yi≤107−107≤xi,yi≤107) — the coordinates of the ii-th animal's lair. It is guaranteed that yi≠0yi≠0. No two lairs coincide.
Output
If the reserve cannot be built, print −1−1. Otherwise print the minimum radius. Your answer will be accepted if absolute or relative error does not exceed 10−610−6.
Formally, let your answer be aa, and the jury's answer be bb. Your answer is considered correct if |a−b|max(1,|b|)≤10−6|a−b|max(1,|b|)≤10−6.
Examples
1
0 1
0.5
3
0 1
0 2
0 -3
-1
2
0 1
1 1
0.625
Note
In the first sample it is optimal to build the reserve with the radius equal to 0.50.5 and the center in (0, 0.5)(0, 0.5).
In the second sample it is impossible to build a reserve.
In the third sample it is optimal to build the reserve with the radius equal to 5858 and the center in (12, 58)(12, 58).
题意:一个圆与X轴相切,问最小的半径,使得圆包含所有给定的点。
题解:显然,所有的点必须都要在y轴的同一边才可以,之后二分半径,求取每一个点在枚举半径的时候的圆心的区间值
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<stack>
#include<cstdlib>
#include <vector>
#include <set>
#include<queue>
#include<map>
using namespace std; #define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
const int maxn = 1e5+;
const ll mod = 1e9+;
const double eps = 1e-; double x[maxn],y[maxn];
long double maxx = 100000000000000000.0;
int n;
bool check(long double k)
{
long double l = -maxx,r = maxx;
long double t;
for(int i=;i<=n;i++)
{
if(y[i] > k*)
return false;
t = sqrt(y[i]*(*k-y[i]));
if(l < x[i]-t)
l = x[i]-t;
if(r > x[i]+t)
r =x[i]+t;
}
return l<r;
}
int main()
{
scanf("%d",&n);
for(int i = ;i <= n;i++)
scanf("%lf %lf",&x[i],&y[i]);
for(int i=;i<=n;i++)
{
if(y[i] * y[n] < )
{
puts("-1");
return ;
}
else
y[i] = max(y[i],-y[i]);
}
long double l = ,r = maxx,mid;
for(int i=;i<=;i++)
{
mid = (l+r)/2.0;
if(check(mid))
r = mid;
else
l = mid;
}
printf("%.8Lf\n",mid);
return ;
}
E - Nature Reserve CodeForces - 1059D的更多相关文章
- [CodeForces]1059D Nature Reserve
大意:给你一个平面上N(N<=100000)个点,问相切于x轴的圆,将所有的点都覆盖的最小半径是多少. 计算几何???Div2的D题就考计算几何???某人昨天上课才和我们说这种计算几何题看见就溜 ...
- Codeforces Round #514 (Div. 2):D. Nature Reserve(二分+数学)
D. Nature Reserve 题目链接:https://codeforces.com/contest/1059/problem/D 题意: 在二维坐标平面上给出n个数的点,现在要求一个圆,能够容 ...
- Nature Reserve
Nature Reserve time limit per test:2 seconds memory limit per test:256 megabytes input:standard inpu ...
- CodeForces - 1059D(二分+误差)
链接:CodeForces - 1059D 题意:给出笛卡尔坐标系上 n 个点,求与 x 轴相切且覆盖了所有给出点的圆的最小半径. 题解:二分半径即可.判断:假设当前二分到的半径是 R ,因为要和 x ...
- Codeforces Round #514 (Div. 2) D. Nature Reserve
http://codeforces.com/contest/1059/problem/D 最大值: 最左下方和最右下方分别有一个点 r^2 - (r-1)^2 = (10^7)^2 maxr<0 ...
- [ CodeForces 1059 D ] Nature Reserve
\(\\\) \(Description\) 你现在有\(N\)个分布在二维平面上的整点\((x_i,y_i)\),现在需要你找到一个圆,满足: 能够覆盖所有的给出点 与\(x\)轴相切 现在需要你确 ...
- CF1059D Nature Reserve
原题链接 网络不好的可以到洛谷上去QwQ 题目大意 有N个点,求与y=0相切的,包含这N个点的最小圆的半径 输入输出样例 输入: 2 0 1 1 1 输出 0.625 感觉最多是蓝题难度? 首先无解的 ...
- D - Nature Reserve(cf514,div2)
题意:给出n(n<=1e5)个点,求一个最小的圆,与x轴相切,并且包含这n个点 思路:我第一想到的是,这个圆一定会经过一个点,再根据与x轴相切,我们可以找到最小的圆,让它包含其余的点,但是如何判 ...
- cf1059D. Nature Reserve(三分)
题意 题目链接 Sol 欲哭无泪啊qwq....昨晚一定是智息了qwq 说一个和标算不一样做法吧.. 显然\(x\)轴是可以三分的,半径是可以二分的. 恭喜你获得了一个TLE的做法.. 然后第二维的二 ...
随机推荐
- css透明边框实现
代码: css: .box1{ background: black; padding:20px; } .box2{ background: #fff; border: 10px soli ...
- 解决Pandoc wasn't found.pdflatex not found on PATH
解决nbconvert failed: Pandoc wasn't found.解决nbconvert failed: pdflatex not found on PATH 问题1描述 500 : I ...
- Shader学习笔记整理
1.常用矩阵 UNITY_MATRIX_V 视口矩阵 UNITY_MATRIX_P 投影矩阵 UNITY_MATRIX_MV 模型矩阵 * 视口矩阵 UNITY_MATRIX_MVP 模型矩阵 * 视 ...
- .net 控制器调用外部链接传参方法
public class RequestHelper { /// <summary> /// 发起post请求 /// </summary> /// <typeparam ...
- myeclipse中如何修改Servlet模板_day01
参考网址:https://jingyan.baidu.com/article/0eb457e536d5a503f1a90593.html 如果你在web项目下创建一个Servlet类,那么它会自带很多 ...
- linux下使用iperf测试服务器带宽
准备工具 1.2台Linux服务器(要求其中至少1台主机为腾讯云主机,另外一台任意主机均可,确保2台主机可以互相访问即可)2.Iperf软件为专业网络性能测试工具. 测试目标 上海地区主机外网带宽是否 ...
- 笨办法学Python(二十四)
习题 24: 更多练习 你离这本书第一部分的结尾已经不远了,你应该已经具备了足够的 Python 基础知识,可以继续学习一些编程的原理了,但你应该做更多的练习.这个练习的内容比较长,它的目的是锻炼你的 ...
- TP5.1:实现分页
前提: (1)为了让分页变得更加好看,我的案例加载了bootstrap和jq的文件,具体操作请参考:http://www.cnblogs.com/finalanddistance/p/9033916. ...
- 深入了解MongoDB
一.介绍: 数据库分为关系型数据库和非关系型数据库 关系型数据库是建立在关系模型上的数据库,主要的有Oracle MySQL Microsoft SQL Server NoSQL是非关系型数据存储的广 ...
- ARM实验3 ——串口实验
uart串口实验 实验内容: 编写UART模块程序,通过串口将信息打印到终端. 实验目的: 熟悉开发环境的使用. 掌握exynos4412处理器的UART功能. 实验平台: FS4412开发板,ecl ...