传送门

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. jQuery遍历节点

    html代码 <div> <p>武汉长乐教育</p> <span>在哪才能真正学习会PHP技术?</span> <a href=&qu ...

  2. js之静态方法与实例方法

    静态方法是指不需要声明类的实例就可以使用的方法. 实例方法是指必须要先使用"new"关键字声明一个类的实例, 然后才可以通过此实例访问的方法. function staticCla ...

  3. 一道Java集合框架题

    问题:某班30个学生的学号为20070301-20070330,全部选修了Java程序设计课程,给出所有同学的成绩(可用随机数产生,范围60-100),请编写程序将本班各位同学的成绩按照从低到高排序打 ...

  4. Refactoring in Coding

    Make changes on existing code for subsequent and constant changes of requirement. Reference:http://w ...

  5. HTML5 笔记之 HTML5 的常见用法介绍

    阅读目录 介绍 网页标题.文章标题.文章段落 介绍 字体大小.字体颜色.字体类型.字体位置.背景颜色 介绍 插入图片 介绍 网页内的超链接.网页间的超链接 介绍 有序列表.无序列表 介绍 表格制作 介 ...

  6. [原创]在Windows Server 2019上配置NAS

    序言 此教程安装的都是最新版本的.由于是当NAS让它非常稳定的运行,所以能不安装的软件尽量不要安装. 一.准备工作 [更新系统] 没啥,就他喵想用个最新的. 右键点击开始键->设置->更新 ...

  7. 运行python文件报SyntaxError:Non-ASCII character '\xe7'

    以下是报错内容: 在文件页头加上: #coding=uft-8 ~解决了~ 记录一下(捂脸)

  8. struts2.3.4.1转换成eclipse项目的过程

    1.在本地安装配置maven. 1.1.从maven官网下载,官网地址:http://maven.apache.org/download.cgi 1.2.配置maven环境变量       例如,我的 ...

  9. Selenium入门系列2 窗口大小控制

    selenium控制窗口最大化.适合手机的宽度.适合pad的宽度等尝试下实例,网站是否做了响应式布局 #coding=utf-8 # 改变浏览器窗口大小.前进后退 from selenium impo ...

  10. HTML入门1—HTML基础学习

    html文档结构 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...