计算几何——圆卡精度cf1059D
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的更多相关文章
- ACM 计算几何中的精度问题(转)
http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...
- 51nod 1172 Partial Sums V2 卡精度的任意模数FFT
卡精度的任意模数fft模板题……这道题随便写个表就能看出规律来(或者说考虑一下实际意义),反正拿到这题之后,很快就会发现他是任意模数fft模板题.然后我就去网上抄了一下板子……我打的是最土的任意模数f ...
- 【TOJ 3005】Triangle(判断点是否在三角形内+卡精度)
描述 Given the coordinates of the vertices of a triangle,And a point. You just need to judge whether t ...
- 01背包+卡精度 Hdu 2955
<span style="color:#3333ff;">/* ---------------------------------------------------- ...
- UVA - 10200 Prime Time 关于 double类型 卡精度
题意: 给定一个区间,a到b, n在区间内,有一个计算素数的公式,n*n+n+41,将n带进去可以得出一个数字.但是这个公式可能不准确,求出这个公式在这个区间内的准确率. 直接模拟就好了,不过要 注意 ...
- 计算几何-LA2218-HPI-第一次卡精度-vijos1087-铁人三项
This article is made by Jason-Cow.Welcome to reprint.But please post the writer's address. http://ww ...
- HDU 3264 Open-air shopping malls (计算几何-圆相交面积)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...
- 2020牛客暑期多校训练营 第二场 B Boundary 计算几何 圆 已知三点求圆心
LINK:Boundary 计算几何确实是弱项 因为好多东西都不太会求 没有到很精通的地步. 做法很多,先说官方题解 其实就是枚举一个点 P 然后可以发现 再枚举一个点 然后再判断有多少个点在圆上显然 ...
- CDOJ 1330 柱爷与远古法阵【高斯消元,卡精度】
柱爷与远古法阵 Time Limit: 125/125MS (Java/Others) Memory Limit: 240000/240000KB (Java/Others) Submit S ...
随机推荐
- DOM中常见的元素获取方式
1.getElementById获取元素 返回的是一个元素对象 var timer = document.getElementById('time'); console.dir 打印返回元 ...
- ARM TK1 安装ROS- indigo
之前安装不成功是因为校园网无法访问源的问题. Ubuntu ARM install of ROS Indigo There are currently builds of ROS for Ubuntu ...
- 如何清除Windows共享登录的用户名密码
打开cmd 1.[查看已记录的登录信息] net use 2.[清除记录] 得关掉你所有打开的samba之后再 net use * /del
- codeforces1175E Minimal Segment Cover 倍增
题目传送门 题意:给出n条平行于x轴的线段,q次询问,每次询问一个区间最少要几条线段来覆盖,若不能覆盖则输出-1. 思路:先考虑贪心,必定是先找到,所有左端点小于等于$x$的线段的右端点最大在哪里,然 ...
- 【FJWC2018】最大真因数
题面 Description 一个合数的真因数是指这个数不包括其本身的所有因数, 例如 6 的正因数有1, 2, 3, 6,其中真因数有 1, 2, 3. 一个合数的最大真因数则是这个数的所有真因数中 ...
- 物理像素,逻辑像素,解决1px的问题
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- leetcode-264-丑数
题目描述: 方法一:堆 O(nlogn) class Solution: def nthUglyNumber(self, n: int) -> int: import heapq heap = ...
- 【命令】Maven命令
当前项目的依赖树: mvn dependency:tree -U.-B.-e -U参数: 该参数能强制让Maven检查所有SNAPSHOT依赖更新,确保集成基于最新的状态,如果没有该参数,Maven默 ...
- USACO 06JAN 牛的舞会 洛谷2863
题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their ...
- NX二次开发-UFUN获取一个图层类别的tag UF_LAYER_ask_category_tag
NX11+VS2013 #include <uf.h> #include <uf_ui.h> #include <uf_layer.h> UF_initialize ...