double 在1e17以后就不能顾及小数,所以用一下加精度的技巧

sqrt(r*r-d*d)=sqrt(r+d)*sqrt(r-d)

遇到误差在几位以内的注意要修改二分的精度,用最大的数据去乘以精度即可

#include<bits/stdc++.h>
using namespace std; const double esp = 1e-;
const double inf = 1e14; double sgn(double x){
if(fabs(x)<esp)return ;
if(x<)return -;
return ;
}
struct Point {
double x,y;
Point(){}
Point (double x,double y):x(x),y(y){}
double distance(Point p){
return hypot(x-p.x,y-p.y);
}
};
struct circle{
Point p;
double r;
circle(){}
circle(Point p,double r):p(p),r(r){}
int relation(Point b){
double dst=b.distance(p);
if(sgn(dst-r)<)return ;
else if(sgn(dst-r)==)return ;
return ;
}
int relationline(double y){//直线只有y=b
double dst=fabs(y-p.y);
if(sgn(dst-r)<)return ;
else if(sgn(dst-r)==)return ;
return ;
}
int pointcrossline(double y,Point &p1,Point &p2){
if(!(*this).relationline(y))return ;
Point a=Point(p.x,y);
double d=fabs(p.y-y);
d=sqrt(r*r-d*d);
if(sgn(d)==){
p1=a,p2=a;
return ;
}
p1=Point(a.x-d,y);
p2=Point(a.x+d,y);
return ;
}
}; #define maxn 100005
Point p[maxn];
int n; //判断半径r是否可行,每个点画个圆和y=r相交,维护L,R即可
int judge(long double r){
long double L=-1e15,R=1e15; for(int i=;i<=n;i++){
if(r*-p[i].y<)return ;
long double d=fabs(r-p[i].y);
d=sqrt(r+d)*sqrt(r-d);//这里要扩大精度
L=max(L,p[i].x-d);R=min(R,p[i].x+d);
}
return L<=R;
} int main(){
cin>>n;
int flag0=,flag1=;
double Min=inf,Max=-inf,M=-inf;
for(int i=;i<=n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
if(p[i].y<) flag0=;
else flag1=;
Min=min(Min,p[i].x);Max=max(Max,p[i].x);
M=max(M,fabs(p[i].y));
}
if(flag0 && flag1){puts("-1");return ;}
if(flag0){
for(int i=;i<=n;i++)
p[i].y *= -;
} double l=,r=inf,mid,ans=-,x=max((Max-Min),M)*esp;
while(x<r-l){
mid=(l+r)/;
if(judge(mid))
ans=mid,r=mid;
else l=mid;
}
printf("%.7lf",ans);
}

计算几何——圆卡精度cf1059D的更多相关文章

  1. ACM 计算几何中的精度问题(转)

    http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...

  2. 51nod 1172 Partial Sums V2 卡精度的任意模数FFT

    卡精度的任意模数fft模板题……这道题随便写个表就能看出规律来(或者说考虑一下实际意义),反正拿到这题之后,很快就会发现他是任意模数fft模板题.然后我就去网上抄了一下板子……我打的是最土的任意模数f ...

  3. 【TOJ 3005】Triangle(判断点是否在三角形内+卡精度)

    描述 Given the coordinates of the vertices of a triangle,And a point. You just need to judge whether t ...

  4. 01背包+卡精度 Hdu 2955

    <span style="color:#3333ff;">/* ---------------------------------------------------- ...

  5. UVA - 10200 Prime Time 关于 double类型 卡精度

    题意: 给定一个区间,a到b, n在区间内,有一个计算素数的公式,n*n+n+41,将n带进去可以得出一个数字.但是这个公式可能不准确,求出这个公式在这个区间内的准确率. 直接模拟就好了,不过要 注意 ...

  6. 计算几何-LA2218-HPI-第一次卡精度-vijos1087-铁人三项

    This article is made by Jason-Cow.Welcome to reprint.But please post the writer's address. http://ww ...

  7. HDU 3264 Open-air shopping malls (计算几何-圆相交面积)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...

  8. 2020牛客暑期多校训练营 第二场 B Boundary 计算几何 圆 已知三点求圆心

    LINK:Boundary 计算几何确实是弱项 因为好多东西都不太会求 没有到很精通的地步. 做法很多,先说官方题解 其实就是枚举一个点 P 然后可以发现 再枚举一个点 然后再判断有多少个点在圆上显然 ...

  9. CDOJ 1330 柱爷与远古法阵【高斯消元,卡精度】

    柱爷与远古法阵 Time Limit: 125/125MS (Java/Others)     Memory Limit: 240000/240000KB (Java/Others) Submit S ...

随机推荐

  1. properties配置文件的基本操作

    对properties的基本操作 public class PropertiesUtil {// 是否是文件public static boolean isFile = false;// 路径publ ...

  2. 解决MSF更新证书错误

    如下图所示提示签名无效下载失败,导致更新不了msf 解决办法如下: echo 'deb http://apt.metasploit.com/ lucid main' > /etc/apt/sou ...

  3. python中while与else的联姻

    循环使用 else 语句在 python 中,for … else 表示这样的意思,for 中的语句和普通的没有区别,else 中的语句会在循环正常执行完(即 for 不是通过 break 跳出而中断 ...

  4. vue生态系统之vuex

    一.webpack生成项目 1.webpack 在需要建立项目的目录中进行初始化项目 E:\vueProject>vue init webpack vuexpj ? Project name v ...

  5. quartz的使用(二.基本过程)

    1.关于各个要素的创建,SchedulerFactoryBean,CronTriggerFactoryBean及JobDetailFactoryBean全部实现spring中的FactoryBean& ...

  6. 前置控制器一DispatcherServlet

    org.springframework.web.servlet.DispatcherServlet 前言 DispatcherServlet是SpringMVC的核心控制器,就像是SpringMVC的 ...

  7. TopCoder[SRM587 DIV 1]:ThreeColorability(900)

    Problem Statement      There is a H times W rectangle divided into unit cells. The rows of cells are ...

  8. [C#]记录一次异常排查,关于using语法、sqlserver数据库session、DBHelper类

    最近在做一个基于asp.net和sqlserver的网站项目,发现网站运行一段时间之后,会报异常: 超时时间已到,但是尚未从池中获取连接.出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小 ...

  9. Codeforces786B

    传送门 n个节点且固定起点最短路,三种加边方法 1.u->v, 边权为w:2. u->[l, r], 边权为w:3. [l, r]->u, 边权为w AC_Code #include ...

  10. HDU-6070 Dirt Ratio(二分+线段树+分数规划)

    目录 目录 思路: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 目录 题意:传送门  原题目描述在最下面.  求\(sum/len\)最小值.\(sum\)是一段区间内不同数字的 ...