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的做法.. 然后第二维的二 ...
随机推荐
- jQuery的选项卡
jQuery的选项卡 下面请看代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- 为什么要使用markdown?
markdown是什么? markdown是一种标记语言,它不是编程语言 为什么要使用markdown? markdown可以使用任何文本编辑器编写和查看 markdown编写的文件可以转化为html ...
- 栅格那点儿事(四A)---栅格的显示与渲染
栅格的显示与渲染 通过前两章的学习,应该对栅格这个东西不那么陌生了.在这一个部分,我们来看看如何展示出栅格数据最美丽的地方,在ArcGIS中栅格的显示与渲染.在进入细节之前,先来看看在ArcGIS中都 ...
- 学习Geodatabase的总结
一.怎样择取自己需要的.有用的资料 1.开始找资料时,首先想到的是ESRI的帮助文档,因为它直接.规范而系统.通读一遍之后,大致了解了Geodatabase的各个方面.再从帮助文档体系结构中选出重要的 ...
- Python开发环境Wing IDE如何检查Python集成
在使用Wing IDE开始代码编辑之前,必须先确保Wing IDE已经成功地找到用户的Python安装位置(如果用户同时安装有多个版本,那么Wing IDE将有限选择最新版).要对这个进行检查,需要调 ...
- 责任链模式(ChainOfResponsibiliby、Filter)
Request 类: package com.demo; public class Request { private String requestStr; public String getRequ ...
- attachEvent方法的作用
用于HTML内代码层和UI层分离.比如,你要给一个按钮增加一个单击事件,你会怎么做?<input type="button" id="theBtn" va ...
- [转]用jwplayer+Nginx搭建视频点播服务器,解决拖动加载慢的问题
flv视频可以采用两种方式发布: 一.普通的HTTP下载方式 二.基于Flash Media Server或Red5服务器的rtmp/rtmpt流媒体方式. 多数知名视频网站都采用的是前一种方式. 两 ...
- 关于Linux主流框架运维工作剖析
LINUX是开源的,这也是最主要的原因,想学Windows,Unix对不起,没有源代码.也正是因为这样,LINUX才能够像雪球一样越滚越大,发展到现在这种规模.今天将为大家带来关于Linux主流框架运 ...
- Objectbox Box的getAll() 函数返回emptylist() 未判断导致崩溃
最近使用了Objectbox作为新项目的数据库后台,Greendao开发团队新力作,但是Objectbox算是比较新的一个东西,现在资料也不多. 今天跟大家分享一个关于Box类的getAll()函数的 ...