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. httpclient请求接口,上传文件附加参数(.net core)

    /// <summary> /// 上传文件 - 武汉站点 /// </summary> [HttpPost] public IActionResult UploadWH(Re ...

  3. 如何查找django安装路径

    需要找到django的安装路径,官方说的那个方法不好用,国内搜索都是都不到的,后来谷歌搜到了很简单 import django django 这样就可以找django的安装路径了,真心不懂为什么国内都 ...

  4. 2018-2-13-win10-uwp-分治法

    title author date CreateTime categories win10 uwp 分治法 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:2 ...

  5. 2018-10-11-WPF-拖动滚动

    title author date CreateTime categories WPF 拖动滚动 lindexi 2018-10-11 14:10:41 +0800 2018-2-13 17:23:3 ...

  6. c语言开发浏览器插件

    c语言开发浏览器插件 senk????sec???

  7. session有效时间

    request.getSession().setMaxInactiveInterval(-1);//session不失效 request.getSession().setMaxInactiveInte ...

  8. boost asio scalability and multithreading

    A library such as Boost.Asio is typically used to achieve greater efficiency. With no need to wait f ...

  9. Component series.liquidFill not exists. Load it first.

    vue 项目中使用水波球报错Component series.liquidFill not exists. Load it first. 解决办法:安装 echarts-liquidfill npm ...

  10. 报数问题:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位

    n = int(input("请输入人数:")) list_p = list(range(1,n+1)) #将所有人放在一个数字里面 count = 0 #设置一个变量,用户计算报 ...