首页 技术 正文
技术 2022年11月16日
0 收藏 396 点赞 3,908 浏览 2204 个字

二分所能形成圆的最大距离,然后将每一条边都向内推进这个距离,最后所有边组合在一起判断时候存在内部点

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath> using namespace std;
#define N 105
#define ll long long
#define eps 1e-7 int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
} struct Point{
double x,y;
Point(double x= , double y=):x(x),y(y){}
}p[N] , poly[N]; typedef Point Vector; struct Line{
Point p;
Vector v;
double ang;
Line(){}
Line(Point p , Vector v):p(p),v(v){ang = atan2(v.y , v.x);}
bool operator<(const Line &m) const{
return dcmp(ang-m.ang)<;
}
}line[N]; Vector operator+(Vector a , Vector b){return Vector(a.x+b.x , a.y+b.y);}
Vector operator-(Vector a , Vector b){return Vector(a.x-b.x , a.y-b.y);}
Vector operator*(Vector a , double b){return Vector(a.x*b , a.y*b);}
Vector operator/(Vector a , double b){return Vector(a.x/b , a.y/b);} double Cross(Vector a , Vector b){return a.x*b.y-a.y*b.x;}
double Dot(Vector a , Vector b){return a.x*b.x+a.y*b.y;}
double Len(Vector a){return sqrt(Dot(a,a));} bool OnLeft(Line L , Point P)
{
return dcmp(Cross(L.v , P-L.p))>;
} Point GetIntersection(Line a , Line b)
{
Vector u = a.p-b.p;
double t = Cross(b.v , u)/Cross(a.v , b.v);
return a.p+a.v*t;
} Vector Normal(Vector a)
{
double l = Len(a);
return Vector(-a.y , a.x)/l;
} int HalfplaneIntersection(Line *L , int n , Point *poly)
{
sort(L , L+n);
int first , last;
Point *p = new Point[n];
Line *q = new Line[n];
q[first=last=] = L[];
for(int i= ; i<n ; i++){
while(first<last && !OnLeft(L[i] , p[last-])) last--;
while(first<last && !OnLeft(L[i] , p[first])) first++;
q[++last] = L[i];
if(fabs(Cross(q[last].v , q[last-].v))<eps){
last--;
if(OnLeft(q[last] , L[i].p)) q[last]=L[i];
}
if(first < last) p[last-] = GetIntersection(q[last-] , q[last]);
}
while(first<last && !OnLeft(q[first] , p[last-])) last--;
if(last-first<=) return ;
p[last] = GetIntersection(q[last] , q[first]);
int m=;
for(int i=first ; i<=last ; i++) poly[m++] = p[i];
return m;
} double calArea(Point *p , int n)
{
if(!n) return ;
double ret = ;
for(int i= ; i<n ; i++){
ret += Cross(p[i-]-p[],p[i]-p[]);
}
return ret/;
} double bin_search(Point *p , int n)
{
double l = , r = 1e8 , m;
Vector unit;
while(r-l>=eps)
{
m = (l+r)/;
for(int i= ; i<=n ; i++){
unit = Normal(p[i]-p[i-]);
line[i-] = Line(p[i-]+unit*m , p[i]-p[i-]);
}
if(HalfplaneIntersection(line , n , poly)) l=m;
else r=m;
}
return l;
} int main()
{
// freopen("in.txt" , "r" , stdin);
int n ;
while(scanf("%d" , &n) , n)
{
for(int i= ; i<n ; i++) scanf("%lf%lf" , &p[i].x , &p[i].y);
p[n] = p[];
printf("%.6f\n" , bin_search(p , n));
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903