bzoj千题计划210:bzoj2642 | Poj3968 | UVALive 4992| hdu 3761 Jungle Outpost
http://www.lydsy.com/JudgeOnline/problem.php?id=2642
题意:
n个瞭望台,形成一个凸n边形。这些瞭望台的保护范围是这个凸包内的任意点。
敌人进攻时,会炸毁一些瞭望台,使得总部暴露在新的保护范围之外。
选择一个点作为总部,使得敌人在任何情况下需要炸坏的瞭望台数目尽量多
任何情况指,假设需炸毁m个,无论炸毁哪m个,剩下的瞭望台都不能保护总部
输出这个数目
凸壳上的点顺时针输入
若敌人只能炸一次,那么总部应选在
所有点i+2到点i组成的有向直线的左侧——半平面交
若敌人能炸两次,那么炸连续的两个点更优
炸毁连续的两个,可以使得到的半平面的左侧尽量靠边
这样交集更容易为空
同理,炸毁k个也是炸毁连续的k个
所以二分炸毁次数k,
判断所有i+k+1和点i构成的有向直线表示的半平面有没有交集即可
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; #define N 50001 typedef long long LL; const double eps=1e-; struct Point
{
double x,y; Point(double x=,double y=):x(x),y(y) {}
}; typedef Point Vector; Point P[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); } 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 < (Line L) const
{
return ang<L.ang;
}
}; Line L[N]; void read(int &x)
{
x=; int f=; char c=getchar();
while(!isdigit(c)) { if(c=='-') f=-; c=getchar(); }
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
x*=f;
} double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
} bool OnLeft(Line L,Point p)
{
return 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;
} bool HalfplaneIntersection(Line *L,int n)
{
// sort(L,L+n); 顺时针输入的点,本来就按极角排好序了
Point *p=new Point[n];
Line *q=new Line[n];
int first,last;
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--;
return last-first>;
} bool check(int n,int k)
{
int m=;
for(int i=;i<n;++i) L[m++]=Line(P[i],P[i]-P[(i+k+)%n]);
return !HalfplaneIntersection(L,m);
} int main()
{
int n,x,y;
int l,r,mid,ans=;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<n;++i)
{
read(x); read(y);
P[i]=Point(x,y);
}
ans=n-;
l=; r=n-;
while(l<=r)
{
mid=l+r>>;
if(check(n,mid)) ans=mid,r=mid-;
else l=mid+;
}
cout<<ans<<'\n';
}
}
bzoj千题计划210:bzoj2642 | Poj3968 | UVALive 4992| hdu 3761 Jungle Outpost的更多相关文章
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划219:bzoj1568: [JSOI2008]Blue Mary开公司
http://www.lydsy.com/JudgeOnline/problem.php?id=1568 写多了就觉着水了... #include<cstdio> #include< ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)
https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...
- bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)
https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
随机推荐
- 关于Map迭代循环,key和value的顺序问题
使用Hashtable,keySet()返回的顺序为降序(key降顺序) ---->6, 5, 4, 3, 2, 1使用TreeMap,keySet()返回的顺序为升序(key升顺序) ---- ...
- 网站遭受大量CC攻击后的应对策略
上周开始我网站遭受了一大波CC攻击,到目前为止仍在继续,作为一个建站小白,我感觉压力好大,又有新的问题要挑战了! 服务器架设在腾讯云,CC攻击很凶猛,带宽瞬间占满,于是在腾讯云后台配置安全组关闭了80 ...
- UE4添加植被Foliage Type
在UE4中的地形渲染上不可避免的需要添加植被,而如果采取手动添加StaticMesh植被的方式则会浪费大量的时间精力. UE4提供了一种批量添加地面植被类型的方式Foliage Type.在编辑器内容 ...
- SICP读书笔记 1.1
SICP CONCLUSION 让我们举起杯,祝福那些将他们的思想镶嵌在重重括号之间的Lisp程序员 ! 祝我能够突破层层代码,找到住在里计算机的神灵! 目录 1. 构造过程抽象 2. 构造数据抽象 ...
- 微软职位内部推荐-Senior PM
微软近期Open的职位: Senior Product Manager My Life & Work Beijing China Our passion is to enable people ...
- PHP Laravel 连接并访问数据库
第一次连接数据库 数据库配置位于config/database.php数据库用户名及密码等敏感信息位于.env文件创建一个测试表laravel_course <?php namespace Ap ...
- java第二次实验报告
课程:Java实验 班级:201352 姓名:池彬宁 学号:20135212 成绩: 指导教师:娄佳鹏 实验日期:15.05.05 实验密级: ...
- Linux换源
Linux换源 前言 最近学校的ipv6坏了,导致从deepin本身获取的源速度极慢,笔者实在忍无可忍,随后在同学指导下换了清华大学ipv4的源 步骤 sudo gedit /etc/apt/sour ...
- mosquitto集群配置
--------------------------------------------------------前言------------------------------------------ ...
- vue 跳转路由传参数用法
// 组件 a <template> <button @click="sendParams">传递</button> </template ...