传送门

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

Input
1
0 1
Output
0.5
Input
3
0 1
0 2
0 -3
Output
-1
Input
2
0 1
1 1
Output
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的更多相关文章

  1. [CodeForces]1059D Nature Reserve

    大意:给你一个平面上N(N<=100000)个点,问相切于x轴的圆,将所有的点都覆盖的最小半径是多少. 计算几何???Div2的D题就考计算几何???某人昨天上课才和我们说这种计算几何题看见就溜 ...

  2. Codeforces Round #514 (Div. 2):D. Nature Reserve(二分+数学)

    D. Nature Reserve 题目链接:https://codeforces.com/contest/1059/problem/D 题意: 在二维坐标平面上给出n个数的点,现在要求一个圆,能够容 ...

  3. Nature Reserve

    Nature Reserve time limit per test:2 seconds memory limit per test:256 megabytes input:standard inpu ...

  4. CodeForces - 1059D(二分+误差)

    链接:CodeForces - 1059D 题意:给出笛卡尔坐标系上 n 个点,求与 x 轴相切且覆盖了所有给出点的圆的最小半径. 题解:二分半径即可.判断:假设当前二分到的半径是 R ,因为要和 x ...

  5. 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 ...

  6. [ CodeForces 1059 D ] Nature Reserve

    \(\\\) \(Description\) 你现在有\(N\)个分布在二维平面上的整点\((x_i,y_i)\),现在需要你找到一个圆,满足: 能够覆盖所有的给出点 与\(x\)轴相切 现在需要你确 ...

  7. CF1059D Nature Reserve

    原题链接 网络不好的可以到洛谷上去QwQ 题目大意 有N个点,求与y=0相切的,包含这N个点的最小圆的半径 输入输出样例 输入: 2 0 1 1 1 输出 0.625 感觉最多是蓝题难度? 首先无解的 ...

  8. D - Nature Reserve(cf514,div2)

    题意:给出n(n<=1e5)个点,求一个最小的圆,与x轴相切,并且包含这n个点 思路:我第一想到的是,这个圆一定会经过一个点,再根据与x轴相切,我们可以找到最小的圆,让它包含其余的点,但是如何判 ...

  9. cf1059D. Nature Reserve(三分)

    题意 题目链接 Sol 欲哭无泪啊qwq....昨晚一定是智息了qwq 说一个和标算不一样做法吧.. 显然\(x\)轴是可以三分的,半径是可以二分的. 恭喜你获得了一个TLE的做法.. 然后第二维的二 ...

随机推荐

  1. maven课程 项目管理利器-maven 3-6 maven中Pom.xml的解析 3星

    本节主要讲了pom中常用的标签 1 常用的标签 2 非常用的标签 1 常用的标签 a 坐标 groupid 反写公司网址+项目名 artifactId 项目名+模块名 version 版本号:3位版本 ...

  2. 从零开始的全栈工程师——js篇(js的异步)

    js中的异步 Javascript语言的执行环境是"单线程"(single thread,就是指一次只能完成一件任务.如果有多个任务,就必须排队,前面一个任务完成,再执行后面一个任 ...

  3. Android Studio Git 分支实践

    新公司有些项目是用的 Git,以前公司都是 svn,为了练手 Git,我个人 APP 用到了,但是仅简单的 git pull/push 的使用,并未用到 Git 精髓,只有当项目中用到,才会紧迫去全面 ...

  4. Linux系统如何设置开机程序自启动

    在Linux系统如何让程序开机时自动启动      核心提示:系统的服务在开机时一般都可以自动启动,那在linux系统下如果想要程序在开机时自动启动怎么办?我们知道在 windows系统“开始”--& ...

  5. SqlServer-Cursor讲解一

    原创文章,转载必需注明出处:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/introduce-for-sqlserver-s-cu ...

  6. POJ-2002 Squares---绕点旋转+Hash

    题目链接: https://vjudge.net/problem/POJ-2002 题目大意: 有一堆平面散点集,任取四个点,求能组成正方形的不同组合方式有多少. 相同的四个点,不同顺序构成的正方形视 ...

  7. CKEditor4x word导入不保存格式的解决方案

    后台上传文档时,目前功能都通过word直接复制黏贴实现,之前和word控件朋友一起测试找个问题,原始代码CK4.X没有找个问题. 第一时间排查config.js的配置发现端倪,测试解决! 由于配合ck ...

  8. 正则表达式 /i /g /m /ig /gi

    正则表达式中/i,/g,/ig,/gi,/m的区别和含义   /i (忽略大小写) /g (全文查找出现的所有匹配字符) /m (多行查找) / /ig(全文查找.忽略大小写) 

  9. centos7安装python3和ipython

    CentOS7下默认系统自带python2.X的版本,这个版本被系统很多程序所依赖,所以不建议删除,如果使用最新的Python3那么我们知道编译安装源码包和系统默认包之间是没有任何影响的,所以可以安装 ...

  10. 【洛谷P1948】[USACO08JAN]电话线

    电话线 题目链接:https://www.luogu.org/problemnew/show/P1948 二分答案+最短路 我们要求一条1~n的路径,使其中的第k+1大的数最小. 二分第k+1大的数的 ...