【二分】【半平面交】Gym - 101309J - Jungle Outpost
发现炸毁的瞭望塔必然是连续的,其余下的部分是一个半平面。
二分答案,枚举所有可能的炸毁情况,做个半平面交,如果交出来面积是0,就可以保证不存在安全区域。
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
#define EPS 0.0000001
#define N 50010
typedef double db;
const db PI=acos(-1.0);
struct Point{db x,y;};
typedef Point Vector;
Vector operator - (const Point &a,const Point &b){return (Vector){a.x-b.x,a.y-b.y};}
Vector operator * (const Vector &a,const db &k){return (Vector){a.x*k,a.y*k};}
Vector operator + (const Vector &a,const Vector &b){return (Vector){a.x+b.x,a.y+b.y};}
db Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
struct Line
{
Point p; Vector v; db ang;
Line(){}
Line(const Point &a,const Point &b)
{
v=b-a;
p=a;
ang=atan2(v.y,v.x);
if(ang<0) ang+=2.0*PI;
}
};
bool operator < (const Line &a,const Line &b){return a.ang<b.ang;}
bool OnLeft(Line l,Point a){return Cross(l.v,a-l.p)>0;}
Point GetJiaodian(Line a,Line b){return a.p+a.v*(Cross(b.v,a.p-b.p)/Cross(a.v,b.v));}
int n;
Point ps[N];
Line q[N];
Line ls[N];
int nn;
Point a[N];
#define INF 10000000000.0
bool BPMJ(int x)
{
int head=1,tail=1;
n=0;
memset(q,0,sizeof(q));
memset(ps,0,sizeof(ps));
for(int i=nn;i>=x+2;--i){
ls[++n]=Line(a[i],a[i-x-1]);
}
for(int i=x+1,j=0;i>=1;++j,--i){
ls[++n]=Line(a[i],a[nn-j]);
}
// ls[++n]=Line((Point){INF,INF},(Point){-INF,INF});
// ls[++n]=Line((Point){-INF,INF},(Point){-INF,-INF});
// ls[++n]=Line((Point){-INF,-INF},(Point){INF,-INF});
// ls[++n]=Line((Point){INF,-INF},(Point){INF,INF});
sort(ls+1,ls+n+1);
q[1]=ls[1];
for(int i=2;i<=n;++i)
{
while(head<tail&&(!OnLeft(ls[i],ps[tail-1]))) --tail;
while(head<tail&&(!OnLeft(ls[i],ps[head]))) ++head;
q[++tail]=ls[i];
if(fabs(Cross(q[tail].v,q[tail-1].v))<EPS)
{
--tail;
if(OnLeft(q[tail],ls[i].p))
q[tail]=ls[i];
}
if(head<tail)
ps[tail-1]=GetJiaodian(q[tail-1],q[tail]);
}
while(head<tail&&(!OnLeft(q[head],ps[tail-1]))) --tail;
if(tail-head<=1){
return 1;
}
ps[tail]=GetJiaodian(q[tail],q[head]);
return head>tail;
}
int main()
{
freopen("jungle.in","r",stdin);
freopen("jungle.out","w",stdout);
scanf("%d",&nn);
for(int i=1;i<=nn;++i) scanf("%lf%lf",&a[i].x,&a[i].y);
int l=1,r=nn-2;
while(l<r){
int mid=(l+r>>1);
if(BPMJ(mid)){
r=mid;
}
else{
l=mid+1;
}
}
printf("%d\n",l);
return 0;
}
【二分】【半平面交】Gym - 101309J - Jungle Outpost的更多相关文章
- UVa 1475 (二分+半平面交) Jungle Outpost
题意: 有n个瞭望塔构成一个凸n边形,敌人会炸毁一些瞭望台,剩下的瞭望台构成新的凸包.在凸多边形内部选择一个点作为总部,使得敌人需要炸毁的瞭望塔最多才能使总部暴露出来.输出敌人需要炸毁的数目. 分析: ...
- [HNOI2012][BZOJ2732] 射箭 [二分+半平面交]
题面 BZOJ题面 思路 半平面交代码讲解戳这里,用的就是这道题 我们射箭的函数形如$y=Ax^2+Bx$ 考虑每一个靶子$(x_0,y_1,y_2)$,实际上是关于$A,B$的不等式限制条件 我们只 ...
- poj 3525Most Distant Point from the Sea【二分+半平面交】
相当于多边形内最大圆,二分半径r,然后把每条边内收r,求是否有半平面交(即是否合法) #include<iostream> #include<cstdio> #include& ...
- 二分+半平面交——poj1279
/* 二分距离,凸包所有边往左平移这个距离,半平面交后看是否还有核存在 */ #include<iostream> #include<cstring> #include< ...
- POJ3525:Most Distant Point from the Sea(二分+半平面交)
pro:给定凸多边形,求凸多边形内的点到最近边界的最远距离. sol:显然是二分一个圆,使得圆和凸多边形不相交,但是这样很难实现. 由于是凸多边形,我们可以把二分圆转化为二分凸多边形的移动. 如果每一 ...
- POJ 3525/UVA 1396 Most Distant Point from the Sea(二分+半平面交)
Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...
- POJ3525-Most Distant Point from the Sea(二分+半平面交)
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3955 ...
- poj3525Most Distant Point from the Sea(半平面交)
链接 求凸多边形内一点距离边最远. 做法:二分+半平面交判定. 二分距离,每次让每条边向内推进d,用半平面交判定一下是否有核. 本想自己写一个向内推进..仔细一看发现自己的平面交模板上自带.. #in ...
- UVALive 4992 Jungle Outpost(半平面交判存)
Jungle Outpost Time limit: 15.000 seconds Description There is a military base lost deep in the jung ...
随机推荐
- java map转json servlet response
1.手写一个map转json的类 1.1 调用方式 //给前端放回json数据 Map<String, Object> map = new HashMap<>(); map.p ...
- LESS使用简介!
我真的真的极度痛苦. 原本用了那么久的LESS,一直都是用编译工具(考拉)进行编译的,今天试了试用less.js来搞,按官网的都一毛一样,然而!就是编译不出来! 我用来擦鼻涕的卫生纸都一下午用了大半卷 ...
- canvas_简单练习
效果图 实现原理: 1.定义canvas标签. 2.获取canvas标签节点,创建canvas2D. 3.在canvas进行画图. 效果代码: <!DOCTYPE html> <ht ...
- 统计Visual Studio项目的代码行数
原文转自 https://blog.csdn.net/tyc129/article/details/74279806 使用Visual Studio 自带的在文件中查找功能中的正则表达式实现代码统计功 ...
- 图论-最近公共祖先-离线Tarjan算法
有关概念: 最近公共祖先(LCA,Lowest Common Ancestors):对于有根树T的两个结点u.v,最近公共祖先表示u和v的深度最大的共同祖先. Tarjan是求LCA的离线算法(先存储 ...
- Hadoop(hadoop,HBase)组件import到eclipse
1.简介: 将源代码import到eclipse可以方便的阅读和修改源码. 2.环境说明: mac mvn工具(Apache Maven 3.3.3 ) 3.hadoop(CDH5.4.2) 1.进入 ...
- MyEclipse部署项目报"Add Deployment". Invalid Subscription Level - Discontinuing this MyEclipse
"Add Deployment". Invalid Subscription Level - Discontinuing this MyEclipse 猜测应该是MyEclipse ...
- Mybatis学习—XML配置文件
总结自 Mybatis官方中文文档 XML 映射配置文件 MyBatis 的配置文件包含了会深深影响 MyBatis 行为的设置(settings)和属性(properties)信息.文档的顶层结构如 ...
- hdu 1455(DFS+好题+经典)
Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 1671(字典树判断前缀)
Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...