题意:一个凸边型,目标在凸边型内且最优。问最多删除几个点使目标暴露在新凸边型外面。

思路:二分+半平面相交。

 #include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std; struct Point
{
double x, y;
Point(double x=, double y=):x(x),y(y) { }
}; typedef Point Vector; Vector operator + (const Vector& A, const Vector& B)
{
return Vector(A.x+B.x, A.y+B.y);
}
Vector operator - (const Point& A, const Point& B)
{
return Vector(A.x-B.x, A.y-B.y);
}
Vector operator * (const Vector& A, double p)
{
return Vector(A.x*p, A.y*p);
}
double Dot(const Vector& A, const Vector& B)
{
return A.x*B.x + A.y*B.y;
}
double Cross(const Vector& A, const Vector& B)
{
return A.x*B.y - A.y*B.x;
}
double Length(const Vector& A)
{
return sqrt(Dot(A, A));
}
Vector Normal(const Vector& A)
{
double L = Length(A);
return Vector(-A.y/L, A.x/L);
} double PolygonArea(vector<Point> p)
{
int n = p.size();
double area = ;
for(int i = ; i < n-; i++)
area += Cross(p[i]-p[], p[i+]-p[]);
return area/;
} // 有向直线。它的左边就是对应的半平面
struct Line
{
Point P; // 直线上任意一点
Vector v; // 方向向量
double ang; // 极角,即从x正半轴旋转到向量v所需要的角(弧度)
Line() {}
Line(Point P, Vector v):P(P),v(v)
{
ang = atan2(v.y, v.x);
}
bool operator < (const Line& L) const
{
return ang < L.ang;
}
}; // 点p在有向直线L的左边(线上不算)
bool OnLeft(const Line& L, const Point& p)
{
return Cross(L.v, p-L.P) > ;
} // 二直线交点,假定交点惟一存在
Point GetLineIntersection(const Line& a, const 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;
} const double eps = 1e-; // 半平面交主过程
vector<Point> HalfplaneIntersection(vector<Line>& L)
{
int n = L.size();
sort(L.begin(), L.end()); // 按极角排序 int first, last; // 双端队列的第一个元素和最后一个元素的下标
vector<Point> p(n); // p[i]为q[i]和q[i+1]的交点
vector<Line> q(n); // 双端队列
vector<Point> ans; // 结果 q[first=last=] = L[]; // 双端队列初始化为只有一个半平面L[0]
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-] = GetLineIntersection(q[last-], q[last]);
}
while(first < last && !OnLeft(q[first], p[last-])) last--; // 删除无用平面
if(last - first <= ) return ans; // 空集
p[last] = GetLineIntersection(q[last], q[first]); // 计算首尾两个半平面的交点 // 从deque复制到输出中
for(int i = first; i <= last; i++) ans.push_back(p[i]);
return ans;
} const int maxn = + ;
int n;
Point P[maxn]; // 连续m个点是否可以保证炸到总部
bool check(int m)
{
vector<Line> lines;
for(int i = ; i < n; i++)
lines.push_back(Line(P[(i+m+)%n], P[i]-P[(i+m+)%n]));//相当于从起点0到((i+m+1)%n)这两点延顺时针方向之间的点被删除。应为向量指向起点0,只有向量左边的点符合要求,右边自然被排除。
return HalfplaneIntersection(lines).empty();
} int solve()
{
if(n == ) return ;
int L = , R = n-, M; // 炸n-3个点一定可以摧毁
while(L < R)
{
M = L + (R-L)/;
if(check(M)) R = M;
else L = M+;
}
return L;
} int main()
{
while(scanf("%d", &n) == && n)
{
for(int i = ; i < n; i++)
{
int x, y;
scanf("%d%d", &x, &y);
P[i] = Point(x, y);
}
printf("%d\n", solve());
}
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. UVALive 4992 Jungle Outpost(半平面交)

    题意:给你n个塔(点)形成一个顺时针的凸包,敌人可以摧毁任何塔,摧毁后剩下的塔再组成凸包 在开始的凸包内选一点为主塔,保证敌人摧毁尽量多塔时主塔都还在现在的凸包内,求出最多摧毁的塔 题解:这题关键就是 ...

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

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

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

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

  5. 【二分】【半平面交】Gym - 101309J - Jungle Outpost

    发现炸毁的瞭望塔必然是连续的,其余下的部分是一个半平面. 二分答案,枚举所有可能的炸毁情况,做个半平面交,如果交出来面积是0,就可以保证不存在安全区域. #include<cstdio> ...

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

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

  7. uva 1475 - Jungle Outpost

    半平面交,二分: 注意,题目的点是顺时针给出的: #include<cstdio> #include<algorithm> #include<cmath> #def ...

  8. UVaLive4992:Jungle Outpost

    传送门 半平面交. 首先,由显然成立法可以证明炸连续的几个总比分散火力效果更佳. 所以二分答案,转化为判定问题,即间隔$ans$个点的连线的半平面交是否为空. 半平面交判定即可. 时间复杂度:$O(N ...

  9. [GodLove]Wine93 Tarining Round #10

    比赛链接: http://www.bnuoj.com/v3/contest_show.php?cid=4159 题目来源: lrj训练指南---几何算法 Flag ID Title   A Board ...

随机推荐

  1. uva10943

    递推  还是比较容易的 /************************************************************************* > Author: ...

  2. 【C++基础】关键字static 局部变量

    1.局部变量 static局部变量和普通局部变量有什么区别:static局部变量只被初始化一次,下一次依据上一次结果值: int test(int j){ static int i=10; i=i+j ...

  3. jasper ireport create a report with parameters without sql query

    I'm new in jasper ireport , and I want to know if it is possible to create a report only with static ...

  4. Servlet课程0426(九)Servlet服务器端创建Cookie和客户端读取Cookie

    服务器端创建Cookie: Win7默认Cookie位置 C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Cookies Cookie ...

  5. SQLite入门与分析(一)---简介

    写在前面:出于项目的需要,最近打算对SQLite的内核进行一个完整的剖析,在此希望和对SQLite有兴趣的一起交流.我知道,这是一个漫长的过程,就像曾经去读Linux内核一样,这个过程也将是辛苦的,但 ...

  6. node.js模块之util模块

    util提供了各种使用的工具.require('util') to access them. Util.format(format,[..]) Returns a formatted string u ...

  7. jquery获取元素索引值index()方法

    jquery的index()方法 搜索匹配的元素,并返回相应元素的索引值,从0开始计数. 如果不给 .index() 方法传递参数,那么返回值就是这个jQuery对象集合中第一个元素相对于其同辈元素的 ...

  8. java中的log中的用法和小结

    Log.logInfo(s.toString());的控制台显示 jog.info的具体用法. import java.io.*; import org.apache.log4j.Logger; im ...

  9. bzoj3156

    斜率优化dp,比较裸 注意int64的运算 ..] of int64;     i,n,h,t:longint;     x,y,z:int64; function g(j,k:int64):doub ...

  10. [转]vs2010 快捷键大全

    vs2010 快捷键大全 VS2010版快捷键 Ctrl+E,D ----格式化全部代码  Ctrl+E,F ----格式化选中的代码  CTRL + SHIFT + B生成解决方案  CTRL + ...