LA4992 Jungle Post
题意
分析
炸连续的比炸单独的好。
二分答案,每种炸连续的构成一些半平面,判断半平面交是否为空。
时间复杂度\(O(T n \log^2)\)
代码
这题卡常,排序的时候必须事先算出幅角,不然会TLE。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<ctime>
#include<cstring>
#define rg register
#define il inline
#define co const
template<class T>il T read()
{
rg T data=0;
rg int w=1;
rg char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
{
data=data*10+ch-'0';
ch=getchar();
}
return data*w;
}
template<class T>T read(T&x)
{
return x=read<T>();
}
using namespace std;
typedef long long ll;
struct Point
{
double x,y;
Point(double x=0,double y=0)
:x(x),y(y){}
};
typedef Point Vector;
Vector operator+(co Vector&A,co Vector&B)
{
return Vector(A.x+B.x,A.y+B.y);
}
Vector operator-(co Vector&A,co Vector&B)
{
return Vector(A.x-B.x,A.y-B.y);
}
Vector operator*(co Vector&A,double p)
{
return Vector(A.x*p,A.y*p);
}
double Dot(co Vector&A,co Vector&B)
{
return A.x*B.x+A.y*B.y;
}
double Cross(co Vector&A,co Vector&B)
{
return A.x*B.y-A.y*B.x;
}
double Length(co Vector&A)
{
return sqrt(Dot(A,A));
}
Vector Normal(co Vector&A)
{
double L=Length(A);
return Vector(-A.y/L,A.x/L);
}
double PolygonArea(vector<Point>p)
{
int n=p.size();
double area=0;
for(int i=1;i<n-1;++i)
area+=Cross(p[i]-p[0],p[i+1]-p[0]);
return area/2;
}
struct Line
{
Point P;
Vector v;
double ang;
Line(Point P=0,Vector v=0)
:P(P),v(v){ang=atan2(v.y,v.x);}
bool operator<(co Line&L)co
{
return ang<L.ang;
}
};
bool OnLeft(co Line&L,co Point&p)
{
return Cross(L.v,p-L.P)>0;
}
Point LineLineIntersection(co Line&a,co 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;
}
co double eps=1e-6;
vector<Point>HalfplaneIntersection(vector<Line>&L)
{
int n=L.size();
sort(L.begin(),L.end());
int first,last;
vector<Point>p(n);
vector<Line>q(n);
vector<Point>ans;
q[first=last=0]=L[0];
for(int i=1;i<n;++i)
{
while(first<last&&!OnLeft(L[i],p[last-1]))
--last;
while(first<last&&!OnLeft(L[i],p[first]))
++first;
q[++last]=L[i];
if(fabs(Cross(q[last].v,q[last-1].v))<eps)
{
--last;
if(OnLeft(q[last],L[i].P))
q[last]=L[i];
}
if(first<last)
p[last-1]=LineLineIntersection(q[last-1],q[last]);
}
while(first<last&&!OnLeft(q[first],p[last-1]))
--last;
if(last-first<=1)
return ans;
p[last]=LineLineIntersection(q[last],q[first]);
for(int i=first;i<=last;++i)
ans.push_back(p[i]);
return ans;
}
co int N=5e4;
int n;
Point P[N];
bool check(int m)
{
vector<Line>lines;
for(int i=0;i<n;++i)
lines.push_back(Line(P[(i+m+1)%n],P[i]-P[(i+m+1)%n]));
return HalfplaneIntersection(lines).empty();
}
int solve()
{
if(n==3)
return 1;
int L=1,R=n-3,res;
while(L<=R)
{
int M=(L+R)>>1;
if(check(M))
res=M,R=M-1;
else
L=M+1;
}
return res;
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;++i)
{
read(P[i].x);read(P[i].y);
}
printf("%d\n",solve());
}
return 0;
}
LA4992 Jungle Post的更多相关文章
- poj 1251 Jungle Roads (最小生成树)
poj 1251 Jungle Roads (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...
- Jungle Roads[HDU1301]
Jungle Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Jungle Roads
Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid ...
- POJ 1251 Jungle Roads (prim)
D - Jungle Roads Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Su ...
- hdu 1301 Jungle Roads 最小生成树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 The Head Elder of the tropical island of Lagrish ...
- POJ 1251 && HDU 1301 Jungle Roads (最小生成树)
Jungle Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/A http://acm.hust.edu.cn/vju ...
- kruskal算法求最小生成树(jungle roads的kruskal解法)
注意: 注意数组越界问题(提交出现runtimeError代表数组越界) 刚开始提交的时候,边集中边的数目和点集中点的数目用的同一个宏定义,但是宏定义是按照点的最大数定义的,所以提交的时候出现了数组越 ...
- 最小生成树Jungle Roads
这道题一定要注意录入方式,我用的解法是prime算法 因为单个字符的录入会涉及到缓冲区遗留的空格问题,我原本是采用c语言的输入方法录入数据的,结果对了,但是提交却一直wrong,后来改成了c++的ci ...
- POJ1251 Jungle Roads 【最小生成树Prim】
Jungle Roads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19536 Accepted: 8970 Des ...
随机推荐
- poj2431 一直Wa
在遍历加油站的时候,会将经过的x加油站放入优先队列,之后将x从数组中删掉,即用最后一个加油站来替代x:这时如果不 “i--”,则会漏掉检查原来的stop[n-1],则可能造成错误. if(stop[i ...
- Cocos2d-x项目移植到WP8系列之九:使用自定义shader
本文原链接:http://www.cnblogs.com/zouzf/p/3995132.html 有时候想得到一些例如灰度图等特殊的渲染效果,就得用到自定义shader,关于shader的一些背景知 ...
- React之JSX语法
1. JSX的介绍 JSX(JavaScript XML)——一种在React组件内部构建标签的类XML语法.react在不使用JSX的情况下一样可以工作,然而使用JSX可以提高组件的可读性,因此 ...
- javascript-实现小抽奖程序
直接上代码 <style> *{ margin: 0; padding:0;} .prize_wrap{ width: 300px; height: 150px; } .prize_wra ...
- no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
1. 使用git克隆项目报错 $ git clone ssh://liuchao@192.168.7.32:29418/platform/Midou Cloning into 'Midou'... U ...
- Define class with itself as generic implementation. Why/how does this work?
https://stackoverflow.com/questions/10709061/define-class-with-itself-as-generic-implementation-why- ...
- 网络数据包头部在linux网络协议栈中的变化
接收时使用skb_pull()不断去掉各层协议头部:发送时使用skb_push()不断添加各层协议头部. 先说说接收: * eth_type_trans - determine the packet' ...
- Elasticsearch 配置优化
cluster.routing.allocation.same_shard.host:true 这会防止同一个shard的主副本存在同一个物理机上(因为如果存在一个机器上,副本的高可用性就没有了). ...
- ButterKnife使用详谈
(1)ButterKnife是什么? 在开发过程中,我们总是会写大量的findViewById和点击事件,像初始view.设置view监听这样简单而重复的操作让人觉得特别麻烦,当然不会偷懒的程序员不是 ...
- 带你彻底明白 Android Studio 打包混淆
前言 在使用Android Studio混淆打包时,该IDE自身集成了Java语言的ProGuard作为压缩,优化和混淆工具,配合Gradle构建工具使用很简单.只需要在工程应用目录的gradle文件 ...