发现炸毁的瞭望塔必然是连续的,其余下的部分是一个半平面。

二分答案,枚举所有可能的炸毁情况,做个半平面交,如果交出来面积是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的更多相关文章

  1. UVa 1475 (二分+半平面交) Jungle Outpost

    题意: 有n个瞭望塔构成一个凸n边形,敌人会炸毁一些瞭望台,剩下的瞭望台构成新的凸包.在凸多边形内部选择一个点作为总部,使得敌人需要炸毁的瞭望塔最多才能使总部暴露出来.输出敌人需要炸毁的数目. 分析: ...

  2. [HNOI2012][BZOJ2732] 射箭 [二分+半平面交]

    题面 BZOJ题面 思路 半平面交代码讲解戳这里,用的就是这道题 我们射箭的函数形如$y=Ax^2+Bx$ 考虑每一个靶子$(x_0,y_1,y_2)$,实际上是关于$A,B$的不等式限制条件 我们只 ...

  3. poj 3525Most Distant Point from the Sea【二分+半平面交】

    相当于多边形内最大圆,二分半径r,然后把每条边内收r,求是否有半平面交(即是否合法) #include<iostream> #include<cstdio> #include& ...

  4. 二分+半平面交——poj1279

    /* 二分距离,凸包所有边往左平移这个距离,半平面交后看是否还有核存在 */ #include<iostream> #include<cstring> #include< ...

  5. POJ3525:Most Distant Point from the Sea(二分+半平面交)

    pro:给定凸多边形,求凸多边形内的点到最近边界的最远距离. sol:显然是二分一个圆,使得圆和凸多边形不相交,但是这样很难实现. 由于是凸多边形,我们可以把二分圆转化为二分凸多边形的移动. 如果每一 ...

  6. 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 ...

  7. POJ3525-Most Distant Point from the Sea(二分+半平面交)

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3955   ...

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

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

  9. UVALive 4992 Jungle Outpost(半平面交判存)

    Jungle Outpost Time limit: 15.000 seconds Description There is a military base lost deep in the jung ...

随机推荐

  1. jQuery取值的一些奇奇怪怪的操作

    语法解释:1. $("#select_id").change(function(){//code...});   //为Select添加事件,当选择其中一项时触发2. var ch ...

  2. bzoj 1046 LIS

    假设我们知道以每个点开始到最后的最长上升序列,设为w[i],这样首先我们在w值中取max,如果询问的值比max大,这样显然就是无解,如果小的话,我们需要求出来字典序最小的方案. 那么对于所有i,我们肯 ...

  3. 八大疯狂的HTML5 Canvas及WebGL动画效果——8 CRAZY ANIMATIONS WITH WEBGL AND HTML5 CANVAS【收藏】

    HTML5, WebGL and Javascript have changed the way animation used to be. Past few years, we can only a ...

  4. mysql 之修改初始密码

    转载自:https://www.cnblogs.com/ivictor/p/5142809.html 为了加强安全性,MySQL5.7为root用户随机生成了一个密码,在error log中,关于er ...

  5. 下载 LFS所需要的源码包的脚本程序及检验方法

    下载 LFS所需要的源码包的脚本程序及检验方法 http://blog.csdn.net/yygydjkthh/article/details/45315143

  6. 如何在苹果官网下载旧版本的Xcode

    如何在苹果官网下载旧版本的Xcode 前段时间XcodeGhost事件让很多应用中招,不乏一些知名的互联网公司开发的应用.事件的起因是开发者使用了非官方的Xcode,这些Xcode带有xcodegho ...

  7. Linux Python apache的cgi配置

    一.找到安装Apache的目录/usr/local/apache2/conf,并对httpd.conf配置文件进行修改 1.加载cgi模块 去掉注释: LoadModule cgid_module m ...

  8. MAC 'readonly' option is set (add ! to override)错误解决

    该错误为当前用户没有权限对文件作修改 输入 :w !sudo tee %

  9. http通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤

    http通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤: (1)    建立TCP连接 在HTTP工作开始之前,Web浏览器首先要通过网络与Web服务器建立连接,该连接是通过TCP来完成 ...

  10. Spring boot 集成hessian - LocalDateTime序列化和反序列化

    - 反序列化 import com.caucho.hessian.HessianException; import com.caucho.hessian.io.AbstractDeserializer ...