bzoj千题计划236:bzoj2300: [HAOI2011]防线修建
http://www.lydsy.com/JudgeOnline/problem.php?id=2300
维护动态凸包,人懒用的set
用叉积判断,不要用斜率
#include<set>
#include<cmath>
#include<cstdio>
#include<iostream> using namespace std; #define N 100001 struct node
{
int x,y; node(int x_=,int y_=):x(x_),y(y_){} bool operator < (node p) const
{
return x<p.x;
}
}e[N]; set<node>S; struct data
{
int ty,x;
}g[N<<]; bool cut[N]; double ans; double Ans[N<<];
int tot; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} node operator - (node A,node B) { return node(A.x-B.x,A.y-B.y); } double Cross(node A,node B) { return A.x*B.y-A.y*B.x; } double getdis(node A,node B)
{
return sqrt((double)(A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
} /*double get_slope(node A,node B)
{
return 1.0*(A.y-B.y)/(A.x-B.x);
}*/ void Insert(node a)
{
set<node>::iterator it=S.lower_bound(a),l=it,r=it,t;
l--;
if(Cross(*r-*l,a-*l)<) return;
ans-=getdis(*r,*l);
while()
{
t=r; r++;
if(r==S.end()) break;
if(Cross(*r-a,*t-a)<) ans-=getdis(*t,*r),S.erase(*t);
else break;
}
while(l!=S.begin())
{
t=l; l--;
if(Cross(*t-a,*l-a)<) ans-=getdis(*t,*l),S.erase(*t);
else break;
}
it=S.upper_bound(a);
ans+=getdis(a,*it);
ans+=getdis(a,*(--it));
S.insert(a);
} int main()
{
freopen("defense.in","r",stdin);
freopen("defense.out","w",stdout);
int n,x,y;
read(n); read(x); read(y);
S.insert(node(,));
S.insert(node(x,y));
S.insert(node(n,));
ans=getdis(node(,),node(x,y))+getdis(node(x,y),node(n,));
int m;
read(m);
for(int i=;i<=m;++i) read(e[i].x),read(e[i].y);
int q;
read(q);
for(int i=;i<=q;++i)
{
read(g[i].ty);
if(g[i].ty==)
{
read(g[i].x);
cut[g[i].x]=true;
}
}
for(int i=;i<=m;++i)
if(!cut[i]) Insert(e[i]);
for(int i=q;i;--i)
if(g[i].ty==) Ans[++tot]=ans;
else Insert(e[g[i].x]);
for(int i=tot;i;--i) printf("%.2lf\n",Ans[i]);
return ;
}
2300: [HAOI2011]防线修建
Time Limit: 10 Sec Memory Limit: 512 MB
Submit: 1042 Solved: 576
[Submit][Status][Discuss]
Description
上图中,A,B,C,D,E点为A国城市,且目前都要保护,那么修建的防线就会是A-B-C-D,花费也就是线段AB的长度+线段BC的长度+线段CD的长度,如果,这个时候撤销B点的保护,那么防线变成下图
Input
Output
对于每个询问输出1行,一个实数v,表示修建防线的花费,保留两位小数
Sample Input
2
1 2
3 2
5
2
1 1
2
1 2
2
Sample Output
5.84
4.47
HINT
bzoj千题计划236:bzoj2300: [HAOI2011]防线修建的更多相关文章
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)
https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...
- bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)
https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
- bzoj千题计划250:bzoj3670: [Noi2014]动物园
http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...
随机推荐
- 蓝牙学习笔记二(Android连接问题)
可以通过以下两点加速蓝牙连接: 1.更新连接参数 interval:连接间隔(connection intervals ),范围在 7.5 毫秒 到 4 秒. latency:连接延迟 ... 还有一 ...
- LeetCode 3Sum Closest (Two pointers)
题意 Given an array S of n integers, find three integers in S such that the sum is closest to a given ...
- redis安装启动和数据操作
redis安装和启动 1.安装包下载地址 >> redis基本数据类型 string(字符串和数值) .list(列表/队列).hashmap(哈希表[键唯一]). set(集合[值唯一] ...
- jquery原理的简单分析,让你扒开jquery的小外套。
引言 最近LZ还在消化系统原理的第三章,因此这部分内容LZ打算再沉淀一下再写.本次LZ和各位来讨论一点前端的内容,其实有关jquery,在很久之前,LZ就写过一篇简单的源码分析.只不过当时刚开始写博客 ...
- 2-Seventeenth Scrum Meeting-20151217
任务安排 成员 今日完成 明日任务 闫昊 写完学习进度记录的数据库操作 写完学习进度记录的数据库操作 唐彬 编写与服务器交互的代码 编写与服务器交互的代码 史烨轩 获取视频url 余帆 本地 ...
- linux读书笔记(5章)
linux读书笔记(5章) 标签(空格分隔): 20135328陈都 第五章 系统调用 5.1 与内核通信 系统调用 让应用程序受限的访问硬件设备 提供创建新进程并与已有进程通信的机制 提供申请操作系 ...
- Python爬虫爬中文却显示Unicode,怎样显示中文--问题解答
首先爬取古诗网站时,显示 原因是因为输出为列表[] 如果写一个循环,输出其中每个元素就为中文了...
- JS基础(三)语句
一.判断语句(PS:一般情况下判断条件最终应该是一个布尔值.) 1.if语句 1)基本格式 if(判断条件){ 如果判断条件成立则执行的语句 }else{ 如果判断条件不成立则执行的语句 } 2)扩展 ...
- Beta阶段敏捷冲刺总结
设想和目标 1. 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 在最开始的时候我们就是为了解决集美大学计算机工程学院网页没有搜索引擎的问题.因为没有搜 ...
- Docker 下 mysql 简单的 主从复制实现
1. 拉取镜像 docker pull mysql: 2. 运行这个镜像 docker run -d --name maser mysql: 3. 安装一些必要的软件 docker exec -it ...