UVaLive4992:Jungle Outpost

传送门

半平面交。

首先,由显然成立法可以证明炸连续的几个总比分散火力效果更佳。

所以二分答案,转化为判定问题,即间隔$ans$个点的连线的半平面交是否为空。

半平面交判定即可。

时间复杂度:$O(Nlog^2N)$

//UVaLive4992
//by Cydiater
//2017.2.1
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <set>
#include <vector>
using namespace std;
#define ll 		long long
#define up(i,j,n)	for(int i=j;i<=n;i++)
#define down(i,j,n)	for(int i=j;i>=n;i--)
#define cmax(a,b)	a=max(a,b)
#define cmin(a,b)	a=min(a,b)
#define db		double
#define Vector 		Point
const int MAXN=1e5+5;
const int oo=0x3f3f3f3f;
const db eps=1e-10;
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘)f=-1;ch=getchar();}
	while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
	return x*f;
}
int dcmp(db x){if(fabs(x)<eps)return 0;else return x<0?-1:1;}
struct Point{
	db x,y;
	Point(db x=0,db y=0):x(x),y(y){}
};
Vector operator + (Point x,Point y){return Vector(x.x+y.x,x.y+y.y);}
Vector operator - (Point x,Point y){return Vector(x.x-y.x,x.y-y.y);}
Vector operator * (Vector x,db p){return Vector(x.x*p,x.y*p);}
Vector operator / (Vector x,db p){return Vector(x.x/p,x.y/p);}
bool operator < (const Vector &x,const Vector &y){return dcmp(x.x-y.x)==0?x.y<y.y:x.x<y.x;}
bool operator == (const Vector &x,const Vector &y){return dcmp(x.x-y.x)==0&&dcmp(x.y-y.y)==0;}
struct Line{
	Point P;
	Vector v;
	db ang;
	Line(){}
	Line(Point P,Vector v):P(P),v(v){ang=atan2(v.y,v.x);}
};
bool operator < (const Line &x,const Line &y){return x.ang<y.ang;}
Point V[MAXN],P[MAXN];
int N,top,head,tail;
Line L[MAXN],q[MAXN];
namespace solution{
	Point Write(){db x=read(),y=read();return Point(x,y);}
	db Cross(Vector x,Vector y){return x.x*y.y-x.y*y.x;}
	bool Onleft(Point P,Line Li){return dcmp(Cross(P-Li.P,Li.v))<0;}
	void Prepare(){
		V[0]=Write();
		down(i,N-1,1)V[i]=Write();
	}
	void Modify(int siz){
		up(i,0,N-1)L[i]=Line(V[i],V[(i+siz)%N]-V[i]);
	}
	Point LineMeet(Line x,Line y){
		db t=Cross(y.v,x.P-y.P)/Cross(x.v,y.v);
		return x.P+x.v*t;
	}
	bool check(){
		head=1;tail=0;q[++tail]=L[0];
		up(i,1,N-1){
			while(head<tail&&!Onleft(P[tail-1],L[i]))tail--;
			while(head<tail&&!Onleft(P[head],L[i]))head++;
			q[++tail]=L[i];
			if(dcmp(q[tail-1].ang-q[tail].ang)==0){
				tail--;
				if(Onleft(L[i].P,q[tail]))q[tail]=L[i];
			}
			if(head<tail)P[tail-1]=LineMeet(q[tail-1],q[tail]);
		}
		while(head<tail&&!Onleft(P[tail-1],q[head]))tail--;
		return tail-head>1;
	}
	void Solve(){
		int leftt=0,rightt=N-1,mid;
		while(leftt+1<rightt){
			mid=(leftt+rightt)>>1;
			Modify(mid);
			if(check())	leftt=mid;
			else		rightt=mid;
		}
		Modify(rightt);
		if(check())	cout<<rightt<<endl;
		else		cout<<leftt<<endl;
	}
}
int main(){
	//freopen("input.in","r",stdin);
	using namespace solution;
	while(scanf("%d",&N)!=EOF){
		Prepare();
		Solve();
	}
	return 0;
}
时间: 2024-10-18 17:03:28

UVaLive4992:Jungle Outpost的相关文章

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 genera

UVALive 4992 Jungle Outpost(半平面交)

题意:给你n个塔(点)形成一个顺时针的凸包,敌人可以摧毁任何塔,摧毁后剩下的塔再组成凸包 在开始的凸包内选一点为主塔,保证敌人摧毁尽量多塔时主塔都还在现在的凸包内,求出最多摧毁的塔 题解:这题关键就是选的主塔在不同的地方,敌人就会摧毁不同的塔来让你的主塔暴露 因此这样想,找出敌人摧毁不同的塔后形成的所有不同的凸包,再求出所有凸包的交就好 具体就是,首先枚举摧毁塔的个数k,再把摧毁任意k个塔所形成的所有不同的凸包求一个交,如果为空就代表了摧毁k个塔一定可以保证无论主塔在哪儿都可以暴露(关键) 而所

UVa 1475 (二分+半平面交) Jungle Outpost

题意: 有n个瞭望塔构成一个凸n边形,敌人会炸毁一些瞭望台,剩下的瞭望台构成新的凸包.在凸多边形内部选择一个点作为总部,使得敌人需要炸毁的瞭望塔最多才能使总部暴露出来.输出敌人需要炸毁的数目. 分析: 在炸毁同样数量的瞭望塔时,如何爆破才能使暴露出的面积最大.那就是集中火力炸掉连续的几个瞭望塔.直觉上是这样的,我不会证明这个结论.因为是连续爆破,所以k次爆破后还保留的部分就是一个半平面,枚举这k个爆破点,如果这些半平面交非空则总部可以设在这里. k值是通过二分来确定的,下界是1,上界是n-3(这

UVA 1475 - Jungle Outpost(二分 + 半平面交)

题目链接:点击打开链接 思路:首先,我们要知道一个贪心结论:敌人如果有k个炸弹, 那么他一定是炸连续的k个点, 这样会使得炸的面积最大.  那么我们只要二分炸弹数mid,每隔mid个点重新建立一个平面, 仍然是n个平面, 代表n种可能情况, 那么如果他们的交存在, 那么司令部只要放在这个平面交的面积内就行了.  所以问题迎刃而解, 二分答案, 用半平面交判断答案是否可行. 细节参见代码: #include <cstdio> #include <cstring> #include &

计算几何 半平面交

LA 4992 && hdu 3761 Jungle Outpost 杭电的有点坑啊..一直爆内存,后来发现大白的半平面交模板那里 point *p = new point[n]; line *q = new line[n]这里出了问题,应该是在函数里面申请不了比较大的数组,所以爆内存..我在全局定义了两个数组就不会爆了.. 本来跑了17s多的,后来半平面交sort( l, l + n ) 被我注释了,就跑了9s多,LA上跑了 2s..应该是输入数据比较好,不用按照极角排序..然后就是照着

[GodLove]Wine93 Tarining Round #10

比赛链接: http://www.bnuoj.com/v3/contest_show.php?cid=4159 题目来源: lrj训练指南---几何算法 Flag ID Title   A Board Wrapping   B Airport   C The Great Divide   D Squares   E Most Distant Point from the Sea   F Triathlon   G Jungle Outpost   H Monster Trap   I Find

几何算法专题

UVA 10652 Board Wrapping UVA 11168 Airport UVA 1396 Most Distant Point from the Sea UVA 1298 Triathlon UVA 1475 Jungle Outpost UVA 10652 Board Wrapping #include<bits/stdc++.h> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fo

POJ1251 Jungle Roads

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24307   Accepted: 11430 Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago.

Jungle Roads

Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensi