题意:给你n个塔(点)形成一个顺时针的凸包,敌人可以摧毁任何塔,摧毁后剩下的塔再组成凸包

   在开始的凸包内选一点为主塔,保证敌人摧毁尽量多塔时主塔都还在现在的凸包内,求出最多摧毁的塔

题解:这题关键就是选的主塔在不同的地方,敌人就会摧毁不同的塔来让你的主塔暴露

因此这样想,找出敌人摧毁不同的塔后形成的所有不同的凸包,再求出所有凸包的交就好

具体就是,首先枚举摧毁塔的个数k,再把摧毁任意k个塔所形成的所有不同的凸包求一个交,如果为空就代表了摧毁k个塔一定可以保证无论主塔在哪儿都可以暴露(关键)

而所有凸包的交可以将其转化为找到所有凸包上的直线求半平面交,接着就是注意敌人摧毁连续的k个塔一定是最优的,所以求半平面交的直线只要n条(理解一下)

最后可以发现答案满足单调性,可以二分答案

再然后这儿有个小trick就是找直线时需要逆时针找(因为半平面交是逆时针来求的)

#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define eps 1E-8
/*注意可能会有输出-0.000*/
#define sgn(x) (x<-eps? -1 :x<eps? 0:1)//x为两个浮点数差的比较,注意返回整型
#define cvs(x) (x > 0.0 ? x+eps : x-eps)//浮点数转化
#define zero(x) (((x)>0?(x):-(x))<eps)//判断是否等于0
#define mul(a,b) (a<<b)
#define dir(a,b) (a>>b)
typedef long long ll;
typedef unsigned long long ull;
const int Inf=<<;
const ll INF=1ll<<;
const double Pi=acos(-1.0);
const int Mod=1e9+;
const int Max=;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {};
int read()
{
scanf("%lf%lf",&x,&y);
}
inline Point operator+(const Point& a)const
{
return Point(x+a.x,y+a.y);
}
inline Point operator*(double a)const
{
return Point(x*a,y*a);
}
inline Point operator-(const Point& a)const
{
return Point(x-a.x,y-a.y);
}
inline bool operator<(const Point& a)const
{
return sgn(x-a.x)<||zero(x-a.x)&&sgn(y-a.y)<;
}
inline bool operator!=(const Point& a)const
{
return !(zero(x-a.x)&&zero(y-a.y));
}
};
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);
}
inline bool operator<(const Line& L)const
{
return ang<L.ang;
}
};
double Dis(Point A,Point B)
{
return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
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;
}
int HarfplaneIntersection(Line *L,int n)
{
sort(L,L+n);
// for(int i=0; i<n; ++i)
// {
// printf("%lf %lf %lf %lf\n",L[i].p.x,L[i].p.y,L[i].v.x,L[i].v.y);
// }
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(zero(Cross(q[last].v,q[last-].v)))
{
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--;
// printf("%d\n",last-first-1);
return max(last-first-,);
}
Point tow[Max];
Line convex[Max];
int Solve(int mid,int n)
{
if(n-mid<=)//剩余的点
return ;
for(int i=; i<n; ++i)
{
//注意注意,半平面交为逆时针
convex[i]=Line(tow[i],tow[(i-mid-+n)%n]-tow[i]);//关键,删除了mid个点后的半平面
}
return HarfplaneIntersection(convex,n);
}
int Dichotomy(int lef,int rig,int n)//二分
{
while(lef<rig)
{
int mid=(lef+rig>>);//代表删多少个点
if(Solve(mid,n))//非空即为需要删除更多的点
{
lef=mid+;
}
else
{
rig=mid;
}
}
return lef;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=; i<n; ++i)
{
tow[i].read();
}
printf("%d\n",Dichotomy(,n,n));
}
return ;
}

UVALive 4992 Jungle Outpost(半平面交)的更多相关文章

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

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

  2. LA 4992 Jungle Outpost(半平面交)

    Jungle Outpost [题目链接]Jungle Outpost [题目类型]半平面交 &题解: 蓝书282 我自己写的代码居然AC了!!! 刘汝佳的说要right要-3什么的,还要特判 ...

  3. uvalive 4992 Jungle Outpost

    题意:一个凸边型,目标在凸边型内且最优.问最多删除几个点使目标暴露在新凸边型外面. 思路:二分+半平面相交. #include<cstdio> #include<cmath> ...

  4. uvalive 7331 Hovering Hornet 半平面交+概率期望

    题意:一个骰子在一个人正方形内,蜜蜂在任意一个位置可以出现,问看到点数的期望. 思路:半平面交+概率期望 #include<cstdio> #include<cstring> ...

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

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

  6. bzoj千题计划210:bzoj2642 | Poj3968 | UVALive 4992| hdu 3761 Jungle Outpost

    http://www.lydsy.com/JudgeOnline/problem.php?id=2642 题意: n个瞭望台,形成一个凸n边形.这些瞭望台的保护范围是这个凸包内的任意点. 敌人进攻时, ...

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

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

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

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

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

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

随机推荐

  1. UIButton的属性设置

    1.背景颜色 btn.backgroundColor = [UIColor redColor]; 2.给按钮添加文字并添加显示状态  [btn setTitle@"播放" forS ...

  2. JS跨域解决方式 window.name

    window.name 传输技术,原本是 Thomas Frank 用于解决 cookie 的一些劣势(每个域名 4 x 20 Kb 的限制.数据只能是字符串.设置和获取 cookie 语法的复杂等等 ...

  3. tableIView 区头的一点问题

    要记得设置区头的高度 否则会出现第一行没区头问题

  4. JavaScript JSON timer(计时器) AJAX HTTP请求 同源策略 跨域请求

    JSON 介绍 1. JSON: JavaScript Object Notation 是一种轻量级的数据交换格式. 它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是 ...

  5. 学习笔记——命令模式Command

    命令模式,将具体操作Receiver封在Command中,调用类只需要知道Command即可.

  6. 关于PS的一些总结

    1.设计给的图,单独用里边的个别图层 打开图 — 新建一个图层(ctrl+n) — (点开上面的窗口排列-垂直排列,左下边下边自动选择改成图层)—选择移动工具,选中要移动的图层,拉到新建文件夹中.  ...

  7. 协同过滤(CF)算法

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  8. android代码格式化方法小结

    转载:http://blog.csdn.net/androidzhaoxiaogang/article/details/7692526 Download the android-formatting. ...

  9. Adobe Flash CC 2014 下载及破解

    来源 :http://prodesigntools.com/adobe-cc-2014-direct-download-links.html 地址:http://trials3.adobe.com/A ...

  10. svn回滚

    有时会因为某些原因会错误提交某些文件: 1,官方版本库升级,自己的库代码也要跟着升级,但发现使用官方代码后有问题,代码需要回滚到可用的版本: 2,拷贝一个项目的代码到另外一个项目,把整个代码目录也拷贝 ...