传送门

半平面交。

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

所以二分答案,转化为判定问题,即间隔$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;
}

UVaLive4992:Jungle Outpost的更多相关文章

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

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

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

    Jungle Outpost Time limit: 15.000 seconds Description There is a military base lost deep in the jung ...

  3. 【二分】【半平面交】Gym - 101309J - Jungle Outpost

    发现炸毁的瞭望塔必然是连续的,其余下的部分是一个半平面. 二分答案,枚举所有可能的炸毁情况,做个半平面交,如果交出来面积是0,就可以保证不存在安全区域. #include<cstdio> ...

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

    题意: 有n个瞭望塔构成一个凸n边形,敌人会炸毁一些瞭望台,剩下的瞭望台构成新的凸包.在凸多边形内部选择一个点作为总部,使得敌人需要炸毁的瞭望塔最多才能使总部暴露出来.输出敌人需要炸毁的数目. 分析: ...

  5. uvalive 4992 Jungle Outpost

    题意:一个凸边型,目标在凸边型内且最优.问最多删除几个点使目标暴露在新凸边型外面. 思路:二分+半平面相交. #include<cstdio> #include<cmath> ...

  6. uva 1475 - Jungle Outpost

    半平面交,二分: 注意,题目的点是顺时针给出的: #include<cstdio> #include<algorithm> #include<cmath> #def ...

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

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

  8. bzoj千题计划210:bzoj2642 | Poj3968 | UVALive 4992| hdu 3761 Jungle Outpost

    http://www.lydsy.com/JudgeOnline/problem.php?id=2642 题意: n个瞭望台,形成一个凸n边形.这些瞭望台的保护范围是这个凸包内的任意点. 敌人进攻时, ...

  9. [GodLove]Wine93 Tarining Round #10

    比赛链接: http://www.bnuoj.com/v3/contest_show.php?cid=4159 题目来源: lrj训练指南---几何算法 Flag ID Title   A Board ...

随机推荐

  1. php面向对象的简单总结 $this $parent self

    面向对象涉及到的比较多,大概总结整理一下php的属性.对象,以及访问方式$this  $parent  self  的使用场景. 1. PHP类属性定义和访问方式: 1 <?php 2 clas ...

  2. shell 强大的awk

    from here 小用法,使用awk来对文件随机抽取n行 awk 'BEGIN{srand()} {print rand()"\t"$0}' input_file | sort ...

  3. Mahout实现基于用户的协同过滤算法

    Mahout中对协同过滤算法进行了封装,看一个简单的基于用户的协同过滤算法. 基于用户:通过用户对物品的偏好程度来计算出用户的在喜好上的近邻,从而根据近邻的喜好推测出用户的喜好并推荐. 图片来源 程序 ...

  4. 学习坤哥的replaceTpl方法

    学习坤哥的方法之后自己写的replaceTpl function replaceTpl(tpl, data){///////////////没有传入可让用户自己定义的方式进行替换,不够灵活       ...

  5. console输出图案

    探索天猫控制台下的图案是怎么制作的 通过它的源码找到以下代码(还原解压代码) 自己也照葫画瓢搞了个以前公司的logo

  6. 关于word文档转成html网页的方法

    在工作中,有时我们可能需要将一个word文档转换成html网页格式,如在写帮助文档的时候,采用office编写,最终却想以网页的格式传到网站的指定目录下供网友直接浏览 这时我们就需要对word文件进行 ...

  7. 【BZOJ2434】[NOI2011]阿狸的打字机 AC自动机+DFS序+树状数组

    [BZOJ2434][NOI2011]阿狸的打字机 Description 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一台老式的打字机.打字机上只有28个按键,分别印有26个小写英文字母和'B'.'P ...

  8. for update 和 t.rowid的区别

    select * from table_name for update; 和 select t.*, t.rowid from table_name t 的区别 前者会对你查询出来的结果加上锁,而后者 ...

  9. poj3349 Snowflake Snow Snowflakes【HASH】

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 49991   Accep ...

  10. hdu2196 Computer【树形DP】【换根法】

    Computer Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...