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(半平面交判存)的更多相关文章

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

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

  2. UVALive 4992 Jungle Outpost(半平面交)

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

  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. poj3525Most Distant Point from the Sea(半平面交)

    链接 求凸多边形内一点距离边最远. 做法:二分+半平面交判定. 二分距离,每次让每条边向内推进d,用半平面交判定一下是否有核. 本想自己写一个向内推进..仔细一看发现自己的平面交模板上自带.. #in ...

  8. poj1474Video Surveillance(半平面交)

    链接 半平面交的模板题,判断有没有核.: 注意一下最后的核可能为一条线,面积也是为0的,但却是有的. #include<iostream> #include <stdio.h> ...

  9. 半平面交模板(O(n*n)&& O(n*log(n))

    摘自http://blog.csdn.net/accry/article/details/6070621 首先解决问题:什么是半平面? 顾名思义,半平面就是指平面的一半,我们知道,一条直线可以将平面分 ...

随机推荐

  1. 金蝶云k3 cloud采购入库单校验日期不通过

    新增采购入库单的时候提示单据日期必须大于等于货主组织在核算系统最后关账日期 解决办法:库存系统和存货核算系统的反关账

  2. go语言从例子开始之Example35.原子计数器

    Go 中最主要的状态管理方式是通过通道间的沟通来完成的,我们在工作池的例子中碰到过,但是还是有一些其他的方法来管理状态的.这里我们将看看如何使用 sync/atomic包在多个 Go 协程中进行 原子 ...

  3. AI比医生更好地发现皮肤癌,未来计算机技术可渗透医院

    未来机器人将取代医生?这可能是事实.为什么这么多年轻人选择计算机行业,因为这是一个趋势.据法新社报道,研究人员周二称,一项计算机技术比人类皮肤科医生在检测皮肤癌方面的表现要好得多,因为这项研究是为了寻 ...

  4. Properties工具类学习

    Properties类学习 1.定义 Properties,java.utils包下的一个工具类,主要用于读取Java的配置文件.各种语言都有自己所支持的配置文件,配置文件中很多变量是经常变动的. 这 ...

  5. spring-boot整合shiro实现权限管理

    1.运行环境 开发工具:intellij idea JDK版本:1.8 项目管理工具:Maven 4.0.0 2.GITHUB地址 https://github.com/nbfujx/springBo ...

  6. php strip_tags()函数 语法

    php strip_tags()函数 语法 作用:剥去字符串中的 HTML 标签 语法:strip_tags(string,allow) 参数: 参数 描述 string  必须,规定要检查的字符串. ...

  7. [CSP-S模拟测试]:序列(主席树)

    题目描述 小$A$把自己之前得到的序列展示给了小$B$,不过这一次,他并不要求小$B$模仿他之前的行为.他给了小$B$一些询问,每个询问都是$l\ r\ x$的形式,要求小$B$数出在序列的第$l$个 ...

  8. leetcode-解题记录 1108. IP 地址无效化

    题目: 给你一个有效的 IPv4 地址 address,返回这个 IP 地址的无效化版本. 所谓无效化 IP 地址,其实就是用 "[.]" 代替了每个 ".". ...

  9. delphi xe2 opencv 学习

    安装环境 delphi xe2 + opencv opencv 从下面的地方下载  https://github.com/Laex/Delphi-OpenCV然后按照 此网站的 说明 一项以项的 安装 ...

  10. 家用NAS配置方案

    对家用用户而言,NAS即一台下载机,硬件需要满足以下几点: 1.稳定性:24×7稳定无故障运行. 2.拓展性:较多的硬盘槽位,便于容量扩容: 3.体积小巧:占地面积小,便于放置. 4.方便远程管理:无 ...