POJ 3525 半平面交+二分
二分所能形成圆的最大距离,然后将每一条边都向内推进这个距离,最后所有边组合在一起判断时候存在内部点
#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));
}
}
POJ 3525 半平面交+二分的更多相关文章
- poj 3525 半平面交求多边形内切圆最大半径【半平面交】+【二分】
<题目链接> 题目大意:给出一个四面环海的凸多边形岛屿,求出这个岛屿中的点到海的最远距离. 解题分析: 仔细思考就会发现,其实题目其实就是让我们求该凸多边形内内切圆的最大半径是多少.但是, ...
- POJ 3525 /// 半平面交 模板
题目大意: 给定n,接下来n行逆时针给定小岛的n个顶点 输出岛内离海最远的点与海的距离 半平面交模板题 将整个小岛视为由许多半平面围成 那么以相同的比例缩小这些半平面 一直到缩小到一个点时 那个点就是 ...
- poj 1755 半平面交+不等式
Triathlon Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6461 Accepted: 1643 Descrip ...
- poj 1279 半平面交核面积
Art Gallery Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6668 Accepted: 2725 Descr ...
- POJ 3525 Most Distant Point from the Sea [半平面交 二分]
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5153 ...
- POJ 3525 Most Distant Point from the Sea (半平面交+二分)
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3476 ...
- 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea
题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...
- HDU 6617 Enveloping Convex(凸包+半平面交+二分)
首先对于这m个点维护出一个凸包M,那么问题就变成了判断凸包P进行放大缩小能不能包含凸包M.(凸包P可以进行中心对称变换再进行放大缩小,见题意) 如何判断合适的相似比呢,我们可以用二分去放大缩小凸包P的 ...
- poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积
/*************** poj 3335 点序顺时针 ***************/ #include <iostream> #include <cmath> #i ...
随机推荐
- Android最佳性能实践(二)——分析内存的使用情况
由于Android是为移动设备开发的操作系统,我们在开发应用程序的时候应当始终把内存问题充分考虑在内.虽然Android系统拥有垃圾自动回收机制,但这并不意味着我们就可以完全忽略何时去分配或释放内存. ...
- rsync同步完整配置
一.需求: 1.对于分公司访问一些服务器(如工程图纸服务器),如果通过Internet上的VPN访问总是觉得速度慢,毕竟带宽有限,为了解决此问题,可以两地建立同步镜像服务器,分公司可以访问本地的镜像服 ...
- STM8s在利用库配置端口的小问题
在应用的时候PA2口需要设置成推挽输出,控制一个外部电源开关,端口初始化程序如下: GPIO_DeInit(GPIOA); GPIO_Init(GPIOA,GPIO_PIN_2,GPIO_MODE_O ...
- SSH2 架构常用注解
1. @Repository 将 DAO 类声明为 Bean 2.@Component 是一个泛化的概念,仅仅表示一个组件 (Bean) ,可以作用在任何层次. 3.@Service 通常作用在业务层 ...
- ActiveX控件(MFC篇)
目录 第1章 VC++6.0创建控件 1 1.1 目标 1 1.1.1 方法 1 1.1.2 属性 1 1.1.3 事件 1 1.2 创建项目 2 1.3 项目结构 ...
- CMD和AMD探秘
踏上前端这条道路以来,我一直以为自己就是个娴熟的切图工,每天只需要做着重复的劳动,切图,做网站.然而,技术的发展是日新月异的,切图工早就面临淘汰.随着浏览器功能越来越完善,前端项目越来越大,代码越来越 ...
- 数据库中User和Schema的关系
如果我们想了解数据库中的User和Schema到底什么关系,那么让我们首先来了解一下数据库中User和Schema到底是什么概念. 在SQL Server2000中,由于架构的原因,Us ...
- ubuntu安装bower失败的解决方法
1.安装nodejs 2.安装npm 3.安装bower 最开始使用 npm install bower -g / sudo npm install bower -g 安装bower后 命令行输入bo ...
- Junit4入门
eclipse自带junit包,可右键直接新建junit类 静态引入:import static org.junit.Assert.* assert.*是类,静态引入会引入assert里的所有静态方法 ...
- 198. 213. 337. House Robber -- 不取相邻值的最大值
198. House Robber You are a professional robber planning to rob houses along a street. Each house ha ...