题意:给你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. Python 学习笔记9

    梦想和我只有一层纸的距离. 接着看Python类:http://www.pythondoc.com/pythontutorial3/classes.html

  2. Stash安装和破解

    参考资料: http://www.unxmail.com/?p=590 上篇介绍了,Atlassian Stash v2.12.1 破解版的下载, 有同学不会安装. 我重新整理了下文档. 表述我的安装 ...

  3. 12c 补丁架构 以及opatch 功能

    cd $ORACLE_HOME/ccr/bin ./emocmrsp oracle@qc550705:/oracle/app/oracle/product/12.1.0.2/db_1/ccr/bin& ...

  4. Oracle Day05 集合与数据处理

    1.集合 --集合操作: 并集.交集.差. select deptno,job,sum(sal) from emp group by deptno,job union select deptno,to ...

  5. 学习笔记——中介者模式Mediator

    中介者模式,A与B之间存在调用对方操作的行为,通过中介者模式,可以去除双方的强引用.如图,A可以通过代理Mediator的方法来调用B的方法,而不需要保存B的引用.

  6. 4-static(静态变量)关键字

    1.使用static声明属性 static声明全局属性2.使用static声明方法 直接通过类名调用3.注意点 使用static方法的时候,只能访问static声明的属性和方法,而非static声明的 ...

  7. 框架基础:ajax设计方案(二)---集成轮询技术

      上一篇文章介绍了ajax技术核心方法,和跨域的问题(只要后台支持跨域默认post就可以),这篇文章讲解一下使用ajax实现的轮询技术,至于iframe,SSE服务器单向推送,以及webSocket ...

  8. php curl调用相关api

    一.基本步骤 1.本次模拟是php的相关post请求,可通过CURLOPT_CUSTOMREQUEST设定相关POST.GET.PUT.DELETE相关适应REST API 2.相关重要的是curl_ ...

  9. Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLIC

    在mysql5中遇到的问题: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) f ...

  10. android网络编程之HttpUrlConnection的讲解--上传大文件

    1.服务器后台使用Servlet开发,这里不再介绍. 2.网络开发不要忘记在配置文件中添加访问网络的权限 <uses-permission android:name="android. ...