计算几何——圆卡精度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 ...
随机推荐
- extend java vm memory parameter in pom.xml
<project> [...] <build> [...] <plugins> <plugin> <groupId>org.apache.m ...
- 配置 jaco机械臂 ros环境
---恢复内容开始--- 终于有机械臂了, 首先先下载包 cd ~/catkin_ws/src git clone https://github.com/Kinovarobotics/kinova-r ...
- Dubbo支持的注册中心有哪些?
1.Dubbo协议(官方推荐协议) 优点: 采用NIO复用单一长连接,并使用线程池并发处理请求,减少握手和加大并发效率,性能较好(推荐使用) 缺点: 大文件上传时,可能出现问题(不使用Dubbo文件上 ...
- JAVA去除抖音视频的水印源码!!!
@PostMapping("geturl") public DataResponse decodeDouiyin(@RequestBody DouyinRequest req ) ...
- delphi 判断两个时间差是否在一个指定范围内
WithinPastYears.WithinPastMonths.WithinPastWeeks.WithinPastDays ... 判断两个时间差是否在一个指定范围内DateUtils.Withi ...
- mysql利用st_distance函数查询附近的点的功能
随着近几年各类移动终端的迅速普及,在手机移动定位app中,附近的人,附近的地点功能十分常见,基于地理位置的服务(LBS)和相关应用也越来越多,而支撑这些应用的最基础技术之一,就是基于地理位置信息的处理 ...
- css清除浮动的几种方法
推荐几种好用的清除浮动方法: 方法1: .clearfix:after { content:"."; display:block; height:; clear:both; vis ...
- python 使用abc实现接口类/虚类(2.2)
python 使用abc实现接口类/虚类 具体类 class BaseA: def run(self): print('base A running') class ChildA(BaseA): de ...
- 由于某些原因无法博客搬家,现在换马甲了 http://blog.csdn.net/qq_32066409
由于位置原因无法博客搬家,现在换马甲到csdn了地址如下http://blog.csdn.net/qq_32066409
- Flex birdeye笔记
1.将官网示例demo运行起来 新建Flex项目,直接将官网src下的demo拷贝到新建的项目的src下 .将官网example-binaries目录下的文件拷贝到新建项目的bin-debug下即可 ...