D. Nature Reserve

题目链接https://codeforces.com/contest/1059/problem/D

题意:

在二维坐标平面上给出n个数的点,现在要求一个圆,能够容纳所有的点,并且与x轴相切的最小半径为多少。

题解:

容易知道圆的纵坐标的绝对值等于其半径,并且半径越大,容纳圆的可能性越大,那么就考虑二分其半径,这样y0值也确定了。

但x值不是很好求。这里我们找到y=y0的那一条线,然后根据半径以及y0,yi值,可以求出当x0在哪一段时,能够包含(xi,yi)这个点,这样我们把问题转化一下,就是求区间的交集了。

但是这题卡精度啊。。二分时换种写法,并且记得long double...具体见代码吧:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+;
int n,m,x;
struct Point{
ll x,y;
bool operator < (const Point &A)const{
return x<A.x;
}
}p[N];
int check(long double mid){
m=;
long double l=-1e17,r=1e17;
for(int i=;i<=n;i++){
long double ll=fabs(p[i].y-mid);
if(mid*mid<ll*ll) return ;
long double dx = sqrt(mid*mid-ll*ll);
l=max(p[i].x-dx,l);
r=min(p[i].x+dx,r);
}
return l<=r;
}
int main(){
scanf("%d",&n);
int f=;
for(int i=;i<=n;i++){
scanf("%I64d%I64d",&p[i].x,&p[i].y);
if(p[i].y*p[].y<) f=;
}
sort(p+,p+n+);
if(f){
cout<<-;
return ;
}
for(int i=;i<=n;i++) p[i].y=fabs(p[i].y);
long double l=,r=1e16,mid;
for(int i=;i<=;i++){
mid=(l+r)/2.0;
if(check(mid)) r=mid;
else l=mid;
}
if(fabs(l-1e16)<) cout<<-;
else printf("%.15f",(double)l);
return ;
}

Codeforces Round #514 (Div. 2):D. Nature Reserve(二分+数学)的更多相关文章

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

  2. Codeforces Round #514 (Div. 2)

    目录 Codeforces 1059 A.Cashier B.Forgery C.Sequence Transformation D.Nature Reserve(二分) E.Split the Tr ...

  3. Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)

    Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...

  4. Codeforces Round #622 (Div. 2) B. Different Rules(数学)

    Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...

  5. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #514 (Div. 2) E. Split the Tree(倍增+贪心)

    https://codeforces.com/contest/1059/problem/E 题意 给出一棵树,每个点都有一个权值,要求你找出最少条链,保证每个点都属于一条链,而且每条链不超过L个点 和 ...

  7. Codeforces Round #514 (Div. 2) C. Sequence Transformation(递归)

    C. Sequence Transformation 题目链接:https://codeforces.com/contest/1059/problem/C 题意: 现在有1~n共n个数,然后执行下面操 ...

  8. Codeforces Round #514 (Div. 2) C. Sequence Transformation 思维构造

    题意 给出一个1-n的集合   gcd 集合里面的所有数  得到的 一个 数   然后自己选择删去一个数   要使得到的数 构成的数列 的字典序最大 思路: gcd所有数 那gcd得到的数肯定要小于数 ...

  9. Codeforces Round #514 (Div. 2) B - Forgery

    这个题我一开始没思路,最后也没思路 2个小时一直没思路 本来还想解释题意的,写了半天发现解释的不是很清楚,你还是google翻译一下吧 这个题解法是这样的: 首先,给你图案里面有很多的点,每个点的周围 ...

随机推荐

  1. 从零开始的Python学习Episode 1

    一.输入与输出 1.输入 input("number:") num = input("number:") 下面一段可以把输入的信息存在num中. 注意:输入的信 ...

  2. PAT-甲级解题目录

    PAT甲级题目:点这里 pat解题列表 题号 标题 题目类型  10001 1001 A+B Format (20 分)  字符串处理  1003 1003 Emergency (25 分) 最短路径 ...

  3. 购物单:Excel的应用

    题目描述: 小明刚刚找到工作,老板人很好,只是老板夫人很爱购物.老板忙的时候经常让小明帮忙到商场代为购物.小明很厌烦,但又不好推辞. 这不,XX大促销又来了!老板夫人开出了长长的购物单,都是有打折优惠 ...

  4. c++容器 STL

    2019-01-24 22:30:32 记录学习PAT的一些知识,有待更新 注:本文是对Algorithm 算法笔记 的总结 C++标准库模板(Standard Template Library,ST ...

  5. Python3 Tkinter-Checkbutton

    1.多选按钮创建 from tkinter import * root=Tk() Checkbutton(root,text='python').pack() root.mainloop() 2.绑定 ...

  6. Python3 Tkinter-Entry

    1.创建 from tkinter import * root=Tk() t1=Entry(root) t1.pack() root.mainloop() 2.绑定变量 from tkinter im ...

  7. ThinkPHP - 2 - SAE(新浪云)部署

    ThinkPHP3.2核心内置了对SAE平台的支持(采用了应用模式的方式),具有自己的独创特性,能够最大程度的使用ThinkPHP的标准特性,让开发人员感受不到SAE和普通环境的差别.甚至可以不学习任 ...

  8. Fafa and the Gates(模拟)

    Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens ...

  9. Alpha 冲刺报告(3/10)

    Alpha 冲刺报告 队名:洛基小队 峻雄(组长) 已完成:开始编写角色的移动脚本 明日计划:继续学习并进行脚本编写 剩余任务:物品背包交互代码 困难:如何把各个模块的脚本整合起来 --------- ...

  10. HDU 2133 What day is it

    http://acm.hdu.edu.cn/showproblem.php?pid=2133 Problem Description Today is Saturday, 17th Nov,2007. ...