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(3
n
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 首先解决问题:什么是半平面? 顾名思义,半平面就是指平面的一半,我们知道,一条直线可以将平面分 ...
随机推荐
- 源码分析--ConcurrentHashMap与HashTable(JDK1.8)
ConcurrentHashMap和Hashtable都是线程安全的K-V型容器.本篇从源码入手,简要说明它们两者的实现原理和区别. 与HashMap类似,ConcurrentHashMap底层也是以 ...
- springBoot+mysql+mybatis demo [基本配置] [遇到的问题]
springBoot+mysql+mybatis的基本配置: 多环境 application.properties spring.profiles.active=dev spring.applicat ...
- toj 4061 矩阵攻击(最大独立集)
题目: 给定一个01 矩阵,其中你可以在0的位置放置攻击装置.每一个攻击装置 (x,y) 都可以按照“日”字攻击其周围八个位置(x−1,y−2),(x−2,y−1),(x+1,y−2),(x+2,y− ...
- max_length 属性
错误:漏掉了 max_length 属性 ERRORS:users.UserProfile.image: (fields.E210) Cannot use ImageField because Pi ...
- 谷歌使用navigator.mediaDevices.getUserMedia 调用摄像头拍照功能,不兼容IE
<template> <div> <!--canvas截取流--> <canvas ref="canvas" ...
- python 爬取<a>标签内href的方法及遇到的问题
原博客地址: https://www.cnblogs.com/dengyg200891/p/6060010.html # -*- coding:utf-8 -*- #python 2.7 #XiaoD ...
- 谷歌已经对Android的开源严防死守
上周,沸沸扬扬的Android垄断案把Google又一次推向了风口浪尖,在这次的垄断案中,Google被欧盟起诉赔偿50亿美元,被起诉的其中一个原因是Google对外宣称Android是开放的,但其实 ...
- 从React Native到微服务,落地一个全栈解决方案
Poplar是一个社交主题的内容社区,但自身并不做社区,旨在提供可快速二次开发的开源基础套件.前端基于React Native与Redux构建,后端由Spring Boot.Dubbo.Zookeep ...
- bzoj4397【Usaco2015 Dec】Breed Counting(前缀和、树状数组)
题目描述 Farmer John's N cows, conveniently numbered 1…N, are all standing in a row (they seem to do so ...
- HDU 6038 Function —— 2017 Multi-University Training 1
Function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total ...