Nature Reserve
There is a forest that we model as a plane and live nn rare animals. Animal number ii has its lair in the point (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=0. Check whether it is possible to build a reserve, and if possible, find the minimum possible radius of such a reserve.
The first line contains one integer n (1≤n≤1e5) — the number of animals.
Each of the next n lines contains two integers xi, yi (−1e7≤xi,yi≤1e7) — the coordinates of the i-th animal's lair. It is guaranteed that yi≠0. No two lairs coincide.
If the reserve cannot be built, print −1. Otherwise print the minimum radius. Your answer will be accepted if absolute or relative error does not exceed 1e−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|)≤1e−6.
1
0 1
0.5
3
0 1
0 2
0 -3
-1
2
0 1
1 1
0.625
In the first sample it is optimal to build the reserve with the radius equal to 0.5 and the center in (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 5/8 and the center in (1/2, 5/8).
题目链接:http://codeforces.com/contest/1059/problem/D
题意:有二维平面上n个点,能否找到一个半径最小的与x轴相切的圆,覆盖全部的点。
分析:首先二分答案,则题目转化为判断半径为定值的与x轴相切的圆能否覆盖全部的点。如果点在x轴上下都有分布,则找不到这样的圆。然后发现既然圆的半径为定值且与x轴相切,则它的圆心是在一条直线上,然后这个圆要覆盖某个点,则以这个点为圆心,半径为r的圆一定也能覆盖这个圆心。再推广发现圆心的那条直线上只有一段区间满足能覆盖该点。于是把全部的点在直线上对应的区间求出来,求出区间交集即可判断这样的圆是否存在。
官方题解:http://codeforces.com/blog/entry/62238
#include<bits/stdc++.h>
#define N 105000
const double INF =1e18;
using namespace std;
struct ss
{
double x,y;
};
ss arr[N];
int n; int check(double r)
{
double cross_l=-INF,cross_r=INF; for(int i=;i<=n;i++)
{
if(arr[i].y>*r)return ; double dis=sqrt(arr[i].y*r*2.0-arr[i].y*arr[i].y);
double nowl=arr[i].x-dis,nowr=arr[i].x+dis; cross_l=max(cross_l,nowl);
cross_r=min(cross_r,nowr);
if(cross_l>cross_r)return ;
}
return ;
} int main()
{
double t;
scanf("%d",&n);
scanf("%lf %lf",&arr[].x,&arr[].y); if(arr[].y>)t=;
else
t=-;
arr[].y*=t; for(int i=;i<=n;i++)
{
scanf("%lf %lf",&arr[i].x,&arr[i].y);
if(arr[i].y*t<)
{
printf("-1\n");
return ;
}
arr[i].y*=t;
} double l=,r=INF;
double ans; int tot=;
while(l<r&&tot--)
{
double mid=(l+r)/;
if(check(mid))
{
ans=mid-1e-;
r=mid;
}
else
l=mid+1e-;
}
printf("%f",ans);
return ;
}
Nature Reserve的更多相关文章
- Codeforces Round #514 (Div. 2):D. Nature Reserve(二分+数学)
D. Nature Reserve 题目链接:https://codeforces.com/contest/1059/problem/D 题意: 在二维坐标平面上给出n个数的点,现在要求一个圆,能够容 ...
- E - Nature Reserve CodeForces - 1059D
传送门 There is a forest that we model as a plane and live nn rare animals. Animal number iihas its lai ...
- [CodeForces]1059D Nature Reserve
大意:给你一个平面上N(N<=100000)个点,问相切于x轴的圆,将所有的点都覆盖的最小半径是多少. 计算几何???Div2的D题就考计算几何???某人昨天上课才和我们说这种计算几何题看见就溜 ...
- 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轴相切,我们可以找到最小的圆,让它包含其余的点,但是如何判 ...
- 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 ...
- cf1059D. Nature Reserve(三分)
题意 题目链接 Sol 欲哭无泪啊qwq....昨晚一定是智息了qwq 说一个和标算不一样做法吧.. 显然\(x\)轴是可以三分的,半径是可以二分的. 恭喜你获得了一个TLE的做法.. 然后第二维的二 ...
- CF1059D Nature Reserve(二分)
简洁翻译: 有N个点,求与y=0相切的,包含这N个点的最小圆的半径 题解 二分半径右端点开小了结果交了二十几次都没A……mmp…… 考虑一下,显然这个半径是可以二分的 再考虑一下,如果所有点都在y轴同 ...
- [ CodeForces 1059 D ] Nature Reserve
\(\\\) \(Description\) 你现在有\(N\)个分布在二维平面上的整点\((x_i,y_i)\),现在需要你找到一个圆,满足: 能够覆盖所有的给出点 与\(x\)轴相切 现在需要你确 ...
随机推荐
- DOS当中的基本操作命令,如何切换磁盘,如何查看文件和文件夹,如何清屏,进入文件夹的命令,javac是什么意思,作用是什么?DOS如何建文件夹?退出文件夹?
如何切换磁盘:使用盘符+:举例 d: 如何查看文件和文件夹 dir/w 如何清屏: cls (clear screen) 进入文件夹的命令cd ,举例cd JDK javac是什么意思,c 是comp ...
- 在mac下使用python抓取数据
2015已经过去,这是2016的第一篇博文! 祝大家新年快乐! 但是我还有好多期末考试! 还没开始复习,唉,一把辛酸泪! 最近看了一遍彦祖的文章叫做 iOS程序员如何使用Python写网路爬虫 所以自 ...
- vue系列之vue cli 3引入ts
插件 Vue2.5+ Typescript 引入全面指南 vue-class-component强化 Vue 组件,使用 TypeScript/装饰器 增强 Vue 组件 vue-property-d ...
- 微信在浏览器打开前的提示页面Android与IOS判断
直接在网上扒一个页面,分分钟搞定! 先看一下效果 这是用微信开发工具打开的样式,直接上完整代码 <!DOCTYPE html> <html lang="en"& ...
- proget Android代码混淆
混淆的时候,还要添加Android.jar,不然,你的程序一篇空白.我就吃了亏. 还有,activity是不能混淆的,因为AndroidMeaxinfast.xml里面会找他.
- 扩展MarkDown表格
一直不知道表格中的:是什么意思,看了GcsSloop的这篇文章后恍然大悟,做下记录. 原文链接 第二行分割线部分可以使用 : 来控制内容状态 MarkDown : | 默认 | 靠右 | 居中 | 靠 ...
- python 二(续)——面向对象编程进阶
1.类的成员 2.类成员修饰符 3.类的特殊成员 在python第二课——面向对象初级,文章中介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一 ...
- xcode6没有prefix.pch预编译文件解决办法
注意到Xcode6创建的工程没有prefix.pch. 于是手动创建. 在other下选择pch文件 接着到工程的build setting下设置开启预编译并配置路径(文件的路径.因为我新建在cofi ...
- Python框架之Django学习笔记(十七)
Django框架之表单(续二) 今天的这篇博客将是Django学习笔记博客的最后一篇,基本每周最少一篇的Django框架学习,坚持到今天也实属不易,当然了,这个框架的学习仅仅是Django框架的基础部 ...
- Python框架之Django学习笔记(十)
又是一周周末,如约学习Django框架.在上一次,介绍了MVC开发模式以及Django自己的MVT开发模式,此次,就从数据处理层Model谈起. 数据库配置 首先,我们需要做些初始配置:我们需要告诉D ...