UVALive 4992 Jungle Outpost(半平面交判存)
Jungle Outpost
Time limit: 15.000 seconds
Description
There is a military base lost deep in the jungle. It is surrounded by n watchtowers with ultrasonic generators. In this problem watchtowers are represented by points on a plane.
Watchtowers generate ultrasonic field and protect all objects that are strictly inside the towers' convex hull. There is no tower strictly inside the convex hull and no three towers are on a straight line.
The enemy can blow up some towers. If this happens, the protected area is reduced to a convex hull of the remaining towers.

The base commander wants to build headquarters inside the protected area. In order to increase its security, he wants to maximize the number of towers that the enemy needs to blow up to make the headquarters unprotected.
Input
The input file contains several test cases, each of them as described below.
The first line of each one of the cases contains a single integer n(3n
50000) -- the number of watchtowers. The next n lines of the input file contain the Cartesian coordinates of watchtowers, one pair of coordinates per line. Coordinates are integer and do not exceed106 by absolute value. Towers are listed in the order of traversal of their convex hull in clockwise direction.
Output
For each test case, write to the output file the number of watchtowers the enemy has to blow up to compromise headquarters protection if the headquarters are placed optimally.
Sample Input
3
0 0
50 50
60 10
5
0 0
0 10
10 20
20 10
25 0
Sample Output
1
2
二分答案,判半平面交是否存在。注意:连续销毁几个点比分开销毁的做法更优。
建立半平面是用直线表示的 。然后直线的左边是代表有面积的,所以要注意下直线的向量方向。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm> using namespace std; #define X first
#define Y second
#define root 1,n,1
#define lr rt<<1
#define rr rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1 typedef long long LL;
typedef pair<int,int> pii;
const int N = ;
const int inf = 1e9+;
const double eps = 1e-;
int n ; inline int dcmp(double x){
if( fabs(x)<eps ) return ;
return x<?-:;
}
struct Point {
double x , y ;
Point(){};
Point(double x,double y):x(x),y(y){};
bool operator < ( const Point &a ) const {
return dcmp(x-a.x) < || ( dcmp(x-a.x)== && dcmp(y-a.y) < );
}
}e[N];
typedef Point Vector;
struct Line {
Point p;
Vector v ; // directional vector
double ang ;
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;
}
}; Point operator - ( Point a , Point b ){ return Point(a.x-b.x,a.y-b.y); }
Point operator + ( Point a , Point b ){ return Point(a.x+b.x,a.y+b.y); }
Point operator * ( Point a , double p ){ return Point(a.x*p,a.y*p); } inline double Cross(Point a , Point 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 HPI( Line* L , int n ) {
sort( L , L + n );
int first , last ; //deque ,
Point *p = new Point[n]; //p[i] is q[i] and q[i+1] 's intersection point
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( 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--;
// delete useless plane
if( last - first <= ) return false ;
return true ;
} Line L[N]; bool ok( int num ) {
int tot = ;
for( int i = ; i < n ; ++i ) {
L[tot++] = Line( e[(i+num+)%n],e[i]-e[(i+num+)%n] ); // convex in clockwise direction
}
if( !HPI(L,tot) ) return true ;
return false ;
} void Run() { for( int i = ; i < n ; ++i ) {
scanf("%lf%lf",&e[i].x,&e[i].y);
}
if( n == ) { puts(""); return ; }
int ans = , l = , r = n - ;
while( l <= r ) {
int mid = (l+r)>>;
if( ok(mid) )
ans = mid , r = mid - ;
else
l = mid + ;
}
printf("%d\n",ans);
} int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
while( scanf("%d",&n)!=EOF ) Run();
}
UVALive 4992 Jungle Outpost(半平面交判存)的更多相关文章
- LA 4992 Jungle Outpost(半平面交)
Jungle Outpost [题目链接]Jungle Outpost [题目类型]半平面交 &题解: 蓝书282 我自己写的代码居然AC了!!! 刘汝佳的说要right要-3什么的,还要特判 ...
- UVALive 4992 Jungle Outpost(半平面交)
题意:给你n个塔(点)形成一个顺时针的凸包,敌人可以摧毁任何塔,摧毁后剩下的塔再组成凸包 在开始的凸包内选一点为主塔,保证敌人摧毁尽量多塔时主塔都还在现在的凸包内,求出最多摧毁的塔 题解:这题关键就是 ...
- uvalive 4992 Jungle Outpost
题意:一个凸边型,目标在凸边型内且最优.问最多删除几个点使目标暴露在新凸边型外面. 思路:二分+半平面相交. #include<cstdio> #include<cmath> ...
- uvalive 7331 Hovering Hornet 半平面交+概率期望
题意:一个骰子在一个人正方形内,蜜蜂在任意一个位置可以出现,问看到点数的期望. 思路:半平面交+概率期望 #include<cstdio> #include<cstring> ...
- UVa 1475 (二分+半平面交) Jungle Outpost
题意: 有n个瞭望塔构成一个凸n边形,敌人会炸毁一些瞭望台,剩下的瞭望台构成新的凸包.在凸多边形内部选择一个点作为总部,使得敌人需要炸毁的瞭望塔最多才能使总部暴露出来.输出敌人需要炸毁的数目. 分析: ...
- bzoj千题计划210:bzoj2642 | Poj3968 | UVALive 4992| hdu 3761 Jungle Outpost
http://www.lydsy.com/JudgeOnline/problem.php?id=2642 题意: n个瞭望台,形成一个凸n边形.这些瞭望台的保护范围是这个凸包内的任意点. 敌人进攻时, ...
- poj3525Most Distant Point from the Sea(半平面交)
链接 求凸多边形内一点距离边最远. 做法:二分+半平面交判定. 二分距离,每次让每条边向内推进d,用半平面交判定一下是否有核. 本想自己写一个向内推进..仔细一看发现自己的平面交模板上自带.. #in ...
- poj1474Video Surveillance(半平面交)
链接 半平面交的模板题,判断有没有核.: 注意一下最后的核可能为一条线,面积也是为0的,但却是有的. #include<iostream> #include <stdio.h> ...
- 半平面交模板(O(n*n)&& O(n*log(n))
摘自http://blog.csdn.net/accry/article/details/6070621 首先解决问题:什么是半平面? 顾名思义,半平面就是指平面的一半,我们知道,一条直线可以将平面分 ...
随机推荐
- JavaScript——正则匹配、正则提取、正则替换
正则匹配 // 匹配日期 var dateStr = '2015-10-10'; var reg = /^\d{4}-\d{1,2}-\d{1,2}$/ console.log(reg.test(da ...
- Electron 无边框窗口最大化最小化关闭功能
Electron 无边框窗口最大化最小化关闭功能 目的 实现无边框窗口,并添加最大化最小化和关闭功能 前提 了解Electron 主进程和渲染进程的通讯 了解 BrowserWindow相关功能 操作 ...
- 微信小程序(16)-- bindtap,catchtap事件绑定的区别
bindtap,catchtap事件绑定的区别,这里就涉及冒泡事件了.bind事件绑定不会阻止冒泡事件向上冒泡,catch事件绑定可以阻止冒泡事件向上冒泡. logs.wxml <view cl ...
- 二、Ajax请求MVC中数据查询表返回datatable
一.Ajax请求MVC中数据查询表返回datatable 解决方式 返回list
- (ACM模板)集合set
#include<iostream> #include<cstdio> #include<set> using namespace std; int main() ...
- [BZOJ5407]girls
也是CF985G... 容斥+三元环计数 CF数据太弱啦 vis没赋初值-1竟然过了QAQ 所以又调了我半个小时才搞掉QAQ 数数真难QAQ 记得要写#include<vector>!!! ...
- orcad原理图与PSPICE模型库名称
Vendor PSpice Model Description Advanced Linear Devices adv_lin.lib Library of op-amps Advanced Line ...
- Linux复制命令cp进阶
cp -a:连同属性和权限也一起复制 cp -i:如果不带该参数,默认覆盖同名文件而不会提醒. cp -u:只拷贝符合以下条件的文件到目标目录:目标目录中不存在的文件或目标目录中文件版本较旧的文件. ...
- Linux下安装gnuplot
sudo apt-get install gnuplot 但是在 terminal 里面输入: gnuplot 提示 Terminal type set to unknown.解决方法是安装 x11: ...
- 前端开发工具-VsCode插件【个人开发常用】
前端开发工具-VsCode插件[个人开发常用] Atom One Dark Theme-主题 Chinese (Simplified) Language Pack for Visual Studio ...