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(3n50000) -- 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 首先解决问题:什么是半平面? 顾名思义,半平面就是指平面的一半,我们知道,一条直线可以将平面分 ...
随机推荐
- Pull Request的正确打开方式(如何在GitHub上贡献开源项目)
Pull Request的正确打开方式(如何在GitHub上贡献开源项目) GitHub的官方帮助如下: Fork A Repo: https://help.github.com/articles/f ...
- MySQL 新建用户和数据库
MySQL 新建用户和数据库 修改MySql的密码为qwe123 /usr/local/bin/mysqladmin -u root -p password qwe123 mysql设置root远程访 ...
- Linux系统基于fork()新进程的创建
作者:严哲璟 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 fork属于系 ...
- Docker的使用(未完待续)
一.帮助命令 docker version docker info docker --help 二.镜像命令 列出机器上所有的镜像 docker images 查找某个镜像 docker search ...
- 【LeetCode】回溯法 backtracking(共39题)
[10]Regular Expression Matching [17]Letter Combinations of a Phone Number [22]Generate Parentheses ( ...
- 【串线篇】SQL映射文件select简单查询标签
一.参数(Parameters)传递 单个参数 基本类型:取值#{hahaha}随便写 多个参数 <!-- public Employee getEmpById(Integer id,Str ...
- mongodb Access control is not enabled for the database 无访问控制解决方案
转载:https://blog.csdn.net/q1056843325/article/details/70941697 今天使用MongoDB时遇到了一些问题 建立数据库连接时出现了warning ...
- vue 父组件数据修改,子组件数据未修改
页面: 父组件 <myfeedback></myfeedback> 子组件 <news></news> myfeedback.vue <te ...
- 15_1.InetAddress
import java.net.InetAddress; import java.net.UnknownHostException; public class InetAdressTest { pub ...
- 人生苦短_我用Python_configparser/yaml对配置文件读取/写入操作_010
第一,我们先开始安装yaml库,configparser是自带库,yaml库是针对读取yml文件,configparser现阶段我只用于读取conf文件 首先:1)对象文件为:data.yml,下面的 ...