bzoj2300【HAOI2011】防线修建
题目描述
上图中,A,B,C,D,E点为A国城市,且目前都要保护,那么修建的防线就会是A-B-C-D,花费也就是线段AB的长度+线段BC的长度+线段CD的长度,如果,这个时候撤销B点的保护,那么防线变成下图
输入格式
输出格式
对于每个询问输出1行,一个实数v,表示修建防线的花费,保留两位小数
提示
题解:
- 考虑倒着把点插入凸包;
- 只需要每次找到点在原凸包的$x$坐标前驱后继删掉不构成凸包的再插入;
- 可以用$splay$维护即可(常数不太好看)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<vector>
#include<stack>
#include<map>
#include<set>
#define Run(i,l,r) for(int i=l;i<=r;i++)
#define Don(i,l,r) for(int i=l;i>=r;i--)
#define ll long long
#define ld double
#define inf 0x3f3f3f3f
#define mk make_pair
#define fir first
#define sec second
#define il inline
#define rg register
#define pb push_back
using namespace std;
const int N=;
int n,m,mx,tx,ty,ch[N][],sz[N],fa[N],vis[N],rt,cnt;
ld now,ans[N<<];
il char gc(){
static char*p1,*p2,s[];
if(p1==p2)p2=(p1=s)+fread(s,,,stdin);
return(p1==p2)?EOF:*p1++;
}
il int rd(){
int x=; char c=gc();
while(c<''||c>'')c=gc();
while(c>=''&&c<='')x=(x<<)+(x<<)+c-'',c=gc();
return x;
}
struct poi{
int x,y;
poi(int _x=,int _y=):x(_x),y(_y){};
bool operator <(const poi&A)const{return x==A.x?y<A.y:x<A.x;}
poi operator -(const poi&A)const{return poi(x-A.x,y-A.y);}
}p[N],q[N],Q[N<<];
int crs(poi A,poi B){return A.x*B.y-A.y*B.x;}
int dot(poi A,poi B){return A.x*B.x+A.y*B.y;}
ld dis(poi A){return sqrt(A.x*A.x+A.y*A.y);}
il void update(int x){sz[x]=sz[ch[x][]]+sz[ch[x][]]+;}
il void rotate(int x,int&k){
int y=fa[x],z=fa[y];
if(y==k)k=x;else ch[z][ch[z][]==y]=x;
int l=ch[y][]==x,r=l^;
fa[x]=z;fa[y]=x;fa[ch[x][r]]=y;
ch[y][l]=ch[x][r],ch[x][r]=y;
update(y);update(x);
}
il void splay(int x,int&k){
for(int y,z;x!=k;rotate(x,k)){
y=fa[x],z=fa[y];
if(y!=k)rotate( (ch[y][]==x)^(ch[z][]==y) ? x : y ,k);
}
}
il void ins(int&k,int x){
if(!k)q[k=++cnt]=p[x];
else {
if(p[x]<q[k])ins(ch[k][],x),fa[ch[k][]]=k;
else ins(ch[k][],x),fa[ch[k][]]=k;
}
update(k);
}
il int find_pre(int k,int x){
int re=;
while(k){
if(q[k]<p[x])re=k,k=ch[k][];
else k=ch[k][];
}
return re;
}
il int find_nxt(int k,int x){
int re=;
while(k){
if(p[x]<q[k])re=k,k=ch[k][];
else k=ch[k][];
}
return re;
}
il void insert(int x){
int T1=find_pre(rt,x),T2=find_nxt(rt,x),t1,t2;
if(crs(p[x]-q[T1],q[T2]-p[x])>=)return;
now -= dis(q[T1]-q[T2]);
for(splay(t1=T1,rt),t2=ch[t1][];sz[t2];){
while(ch[t2][])t2=ch[t2][];
splay(t2,ch[t1][]);
if(crs(q[t1]-q[t2],p[x]-q[t1])>=){
now -= dis(q[t1]-q[t2]);
fa[ch[t2][]=ch[t1][]]=t2;
update(rt=t2);
t1=t2,t2=ch[t1][];
}else break;
}
now += dis(p[x]-q[t1]);
for(splay(t1=T2,rt),t2=ch[t1][];sz[t2];){
while(ch[t2][])t2=ch[t2][];
splay(t2,ch[t1][]);
if(crs(q[t1]-q[t2],p[x]-q[t1])<=){
now -= dis(q[t1]-q[t2]);
fa[ch[t2][]=ch[t1][]]=t2;
update(rt=t2);
t1=t2,t2=ch[t1][];
}else break;
}
now += dis(p[x]-q[t1]);
ins(rt,x);
}
int main(){
#ifndef ONLINE_JUDGE
freopen("bzoj2300.in","r",stdin);
freopen("bzoj2300.out","w",stdout);
#endif
mx=rd();tx=rd();ty=rd();n=rd();
for(int i=;i<=n;++i)p[i].x=rd(),p[i].y=rd();
p[]=poi(,);ins(rt,);
p[n+]=poi(mx,);ins(rt,n+);
p[n+]=poi(tx,ty);ins(rt,n+);
now = dis(p[]-p[n+]) + dis(p[n+]-p[n+]);
m=rd();for(int i=;i<=m;++i){Q[i].x=rd();if(Q[i].x&)vis[Q[i].y=rd()]=;}
for(int i=;i<=n;++i)if(!vis[i])insert(i);
for(int i=m;i;--i)if(Q[i].x&)insert(Q[i].y);else ans[i]=now;
for(int i=;i<=m;++i)if(Q[i].x==)printf("%.2lf\n",ans[i]);
return ;
}//by tkys_Austin;bzoj2300
bzoj2300【HAOI2011】防线修建的更多相关文章
- bzoj千题计划236:bzoj2300: [HAOI2011]防线修建
http://www.lydsy.com/JudgeOnline/problem.php?id=2300 维护动态凸包,人懒用的set 用叉积判断,不要用斜率 #include<set> ...
- BZOJ2300[HAOI2011]防线修建——非旋转treap+凸包(平衡树动态维护凸包)
题目描述 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上层现在还犹豫不决,到底该把哪些城市作为保护对象呢?又由于 ...
- BZOJ2300: [HAOI2011]防线修建
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2300 (我只是在发以前写过的题.. 因为题目没说强制在线,所以离线乱搞就可以了.先把点删掉然后 ...
- 2019.02.21 bzoj2300: [HAOI2011]防线修建(set+凸包)
传送门 题意:动态维护凸包周长. 思路: 见这篇求面积的吧反正都是一个套路. 代码: #include<bits/stdc++.h> #define int long long #defi ...
- 【BZOJ2300】[HAOI2011]防线修建 set维护凸包
[BZOJ2300][HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可 ...
- 【BZOJ 2300】 2300: [HAOI2011]防线修建 (动态凸包+set)
2300: [HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上 ...
- BZOJ 2300: [HAOI2011]防线修建( 动态凸包 )
离线然后倒着做就变成了支持加点的动态凸包...用平衡树维护上凸壳...时间复杂度O(NlogN) --------------------------------------------------- ...
- [luogu P2521] [HAOI2011]防线修建
[luogu P2521] [HAOI2011]防线修建 题目描述 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国 ...
- P2521 [HAOI2011]防线修建
题目链接:P2521 [HAOI2011]防线修建 题意:给定点集 每次有两种操作: 1. 删除一个点 (除开(0, 0), (n, 0), 与指定首都(x, y)) 2. 询问上凸包长度 至于为什么 ...
- 【题解】P2521 [HAOI2011]防线修建(动态凸包)
[题解]P2521 [HAOI2011]防线修建(动态凸包) 凸包是易插入不好删除的东西,按照剧情所以我们时光倒流 然后问题就是维护凸包的周长,支持加入 本来很简单,但是计算几何就是一些小地方经验不足 ...
随机推荐
- python3 拼接字符串的7种方法
1.直接通过(+)操作符拼接 1 2 >>> 'Hello' + ' ' + 'World' + '!' 'Hello World!' 使用这种方式进行字符串连接的操作效率低下,因为 ...
- Leetcode_3. Find the longest substring without repeating characters
3. Find the longest substring without repeating characters Given a string, find the length of the lo ...
- LEETCODE —— Unique Paths II [Dynamic Programming]
唯一路径问题II Unique Paths II Follow up for "Unique Paths": Now consider if some obstacles are ...
- tee命令详解
基础命令学习目录首页 参考:http://man.linuxde.net/tee tee命令用于将数据重定向到文件,另一方面还可以提供一份重定向数据的副本作为后续命令的stdin.简单的说就是把数据重 ...
- react-native ListView 性能问题
常见性能问题已经有很多答案,这里要说的是使用ListView时注意的地方, ListView的容器需要设定一个固定高度, 不然ListView中的item过多,会把整体页面撑开,设置的 remo ...
- Python20 - Day08
异常处理 一.什么是异常? 异常就是程序运行时发生错误的信号(在程序出现错误时,则会产生一个异常,若程序没有处理他,则会抛出该异常,程序的运行也会停止) 错误分成两种: 1.语法错误 2.逻辑错误 二 ...
- 安卓端通过http对Mysql进行增删改查
各类it学习视频,大家都可以看看哦!我自己本人都是通过这些来学习it只知识的! 下面是视频链接转自:http://www.cnblogs.com/yzxk/p/4749440.html Android ...
- 1~n中1的和
题目:给定一个十进制的正整数,写下从1开始,到N的所有整数,然后数一下其中出现“1”的个数: 要求:写一个函数f(n),返回1到n之间出现“1“的个数, 思路: 1.先判断这个数共多少位,假设为n位: ...
- 【CSAPP笔记】1. 位、字节、整型
<Computer Systems a Programmer's Perspective>,机械工业出版社.中文译名<深入理解计算机系统>.作者:(美)Randal E.Bry ...
- Good Time 冲刺 一
2018/6/14 我们组之前没有开发小程序的经验,所以在尝试中不断探索与学习.在完成小程序的初步注册和界面完善后,我们组开始进行开发任务. 1.1成员简述: 王怡镔:“今天主要学习小程序开发知识及相 ...