蓝书半平面交例题

#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=;
const double eps=1e-;
int n;
struct vec{
double x,y;
vec(double x=,double y=):x(x),y(y){}
vec operator-(vec& a){
return vec(x-a.x,y-a.y);
}
vec operator+(vec&a){
return vec(x+a.x,y+a.y);
}
}po[maxn],v[maxn],v2[maxn],g[maxn];
vec operator*(vec a,double t){return vec(a.x*t,a.y*t);}
double cross(vec a,vec b){return a.x*b.y-b.x*a.y;}
struct lin{
vec p,v;
double ang;
lin(){}
lin(vec p,vec v):p(p),v(v){ang=atan2(v.y,v.x);}
bool operator<(const lin&a)const{
return ang<a.ang;
}
}ll[maxn],q[maxn];
bool onl(lin L,vec p){
return cross(L.v,p-L.p)>;
}
vec qj(lin a,lin b){
vec u=a.p-b.p;
double t=cross(b.v,u)/cross(a.v,b.v);
return a.v*t+a.p;
}
vec nor(vec a){
double len=sqrt(a.x*a.x+a.y*a.y);
return vec(-a.y/len,a.x/len);
}
int halfj(){
sort(ll,ll+n);
int head,tail;
q[head=tail=]=ll[];
for(int i=;i<n;++i){
while(head<tail&&!onl(ll[i],g[tail-]))tail--;
while(head<tail&&!onl(ll[i],g[head]))head++;
q[++tail]=ll[i];
if(fabs(cross(q[tail].v,q[tail-].v))<eps){
--tail;if(onl(q[tail],ll[i].p))q[tail]=ll[i];
}
if(head<tail)g[tail-]=qj(q[tail-],q[tail]);
}
while(head<tail&&!onl(q[head],g[tail-]))--tail;
if(tail-head<=)return ;
return ;
}
int main(){
while(scanf("%d",&n)==&&n){
int m,x,y;
for(int i=;i<n;++i){
scanf("%d%d",&x,&y);po[i]=vec(x,y);
}
for(int i=;i<n;++i){v[i]=po[(i+)%n]-po[i];v2[i]=nor(v[i]);}
double l=,r=,mid;
while(r-l>1e-){
mid=(l+r)/;
for(int i=;i<n;++i)ll[i]=lin(v2[i]*mid+po[i],v[i]);//这里必须先写乘法再写加法才能过编译,可能是我这种重定义的问题;
if(halfj())l=mid;else r=mid;
}
printf("%.6lf\n",l);
}
system("pause");
return ;
}
/*
4
0 0
10000 0
10000 10000
0 10000
3
0 0
10000 0
7000 1000
6
0 40
100 20
250 40
250 70
100 90
0 70
3
0 0
10000 10000
5000 5001
0
*/

la3890(半平面交)的更多相关文章

  1. 【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)

    按逆时针顺序给出n个点,求它们组成的多边形的最大内切圆半径. 二分这个半径,将所有直线向多边形中心平移r距离,如果半平面交不存在那么r大了,否则r小了. 平移直线就是对于向量ab,因为是逆时针的,向中 ...

  2. 【BZOJ-2618】凸多边形 计算几何 + 半平面交 + 增量法 + 三角剖分

    2618: [Cqoi2006]凸多边形 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 959  Solved: 489[Submit][Status] ...

  3. 【CSU1812】三角形和矩形 【半平面交】

    检验半平面交的板子. #include <stdio.h> #include <bits/stdc++.h> using namespace std; #define gg p ...

  4. 简单几何(半平面交+二分) LA 3890 Most Distant Point from the Sea

    题目传送门 题意:凸多边形的小岛在海里,问岛上的点到海最远的距离. 分析:训练指南P279,二分答案,然后整个多边形往内部收缩,如果半平面交非空,那么这些点构成半平面,存在满足的点. /******* ...

  5. poj 3335(半平面交)

    链接:http://poj.org/problem?id=3335     //大牛们常说的测模板题 ------------------------------------------------- ...

  6. poj3525Most Distant Point from the Sea(半平面交)

    链接 求凸多边形内一点距离边最远. 做法:二分+半平面交判定. 二分距离,每次让每条边向内推进d,用半平面交判定一下是否有核. 本想自己写一个向内推进..仔细一看发现自己的平面交模板上自带.. #in ...

  7. poj1474Video Surveillance(半平面交)

    链接 半平面交的模板题,判断有没有核.: 注意一下最后的核可能为一条线,面积也是为0的,但却是有的. #include<iostream> #include <stdio.h> ...

  8. 半平面交模板(O(n*n)&& O(n*log(n))

    摘自http://blog.csdn.net/accry/article/details/6070621 首先解决问题:什么是半平面? 顾名思义,半平面就是指平面的一半,我们知道,一条直线可以将平面分 ...

  9. POJ2451 Uyuw's Concert(半平面交)

    题意就是给你很多个半平面,求半平面交出来的凸包的面积. 半平面交有O(n^2)的算法,就是每次用一个新的半平面去切已有的凸包,更新,这个写起来感觉也不是特别好写. 另外一个O(nlogn)的算法是将半 ...

随机推荐

  1. 使用JFinal实现使用MVC获取表单中的数据并将提示信息返回给另一jsp页面。

    1.包结构 2.我们需要对web.xml进行配置: <?xml version="1.0" encoding="UTF-8"?> <web-a ...

  2. slam14讲证明构成李代数

  3. Eigen解线性方程组

    一. 矩阵分解: 矩阵分解 (decomposition, factorization)是将矩阵拆解为数个矩阵的乘积,可分为三角分解.满秩分解.QR分解.Jordan分解和SVD(奇异值)分解等,常见 ...

  4. PAT 1051 复数乘法(15 )(代码+思路)

    1051 复数乘法(15 分) 复数可以写成 (A+Bi) 的常规形式,其中 A 是实部,B 是虚部,i 是虚数单位,满足 i​2​​=−1:也可以写成极坐标下的指数形式 (R×e​(Pi)​​),其 ...

  5. UVALive - 3266 (贪心) 田忌赛马

    耳熟能详的故事,田忌赛马,第一行给出田忌的马的速度,第二行是齐王的马的速度,田忌赢一场得200,输一场失去200,平局不得也不失,问最后田忌最多能得多少钱? 都知道在故事里,田忌用下等马对上等马,中等 ...

  6. Hyperscan与Snort的集成方案

    概况 Hyperscan作为一款高性能的正则表达式匹配库,非常适用于部署在诸如DPI/IPS/IDS/NGFW等网络解决方案中.Snort (https://www.snort.org) 是目前应用最 ...

  7. mtcp的快速编译(连接)

    mtcp的快速编译 http://mos.kaist.edu/guide/config/03_build_mtcp.html 介绍DPDK中使用mtcp的文档 https://dpdksummit.c ...

  8. Windows cordova build Error: Could not find gradle wrapper within Android SDK.(转)

    原文:http://blog.csdn.net/kongxx/article/details/68954151 在Windows7上运行 “cordova build Android” 报错,如下: ...

  9. RTTI(运行时类型识别)

    运行时类型识别(Run-time type identification , RTTI),是指在只有一个指向基类的指针或引用时,确定所指对象的准确类型的操作.其常被说成是C++的四大扩展之一(其他三个 ...

  10. Codeforces 749C. Voting 模拟题

    C. Voting time limit per test: 1 second memory limit per test: 256 megabytes input: standard input o ...