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的子节点 那么 ...
随机推荐
- 浅谈 iOS 中的 Activity Indicator
Activity Indicator 是iOS开发中必不可少的一个视图.本文就简单地总结一下这个Activity Indicator 的使用方法. 默认 Activity Indicator 以下的函 ...
- Jmeter目录文件讲解
1.bin:核心可执行文件,包含配置 2.windows启动文件:jmeter.bat mac或linux启动文件:jmeter jmeter-server:mac或linux分布式压测启动文件 jm ...
- 绕WAF&安全狗新姿势
俗话说只要思路宽,绕狗绕的欢.前段时间我有尝试着用以下的方法绕狗,效果还不错.不过这方法呢也许这段时间可以绕过,过段时间可能就失效了,大家还是要多去尝试找到更多的方法. 举例-->整型注入 绕过 ...
- PAT-1004 Counting Leaves
1004 Counting Leaves (30 分) A family hierarchy is usually presented by a pedigree tree. Your job is ...
- 1065 A+B and C
同样是一题会产生溢出的题,不同的是这个用大数类很麻烦,因为有负数的可能性 不妨利用溢出的特性来解题:两个整数和为负数 或者 两个负数和为正数,那么就溢出了. #include<bits/stdc ...
- 【SE】Week7 : Silver Bullet & Cathedral and Bazaar & Big Ball of Mud & Waterfall ...
1. Silver Bullet No Silver Bullet: Essence and Accidents of Software Engineering —— 无银弹理论,出自于美国1999年 ...
- LeetCode 638 Shopping Offers
题目链接: LeetCode 638 Shopping Offers 题解 dynamic programing 需要用到进制转换来表示状态,或者可以直接用一个vector来保存状态. 代码 1.未优 ...
- 数学口袋精灵app(小学生四则运算app)开发需求
数学口袋精灵APP,摒除了传统乏味无趣学习数学四则运算的模式,采用游戏的形式,让小朋友在游戏中学习,培养了小朋友对数学的兴趣,让小朋友在游戏中运算能力得到充分提升.快乐学习,成长没烦恼! 项目名字:“ ...
- ELK 性能(2) — 如何在大业务量下保持 Elasticsearch 集群的稳定
ELK 性能(2) - 如何在大业务量下保持 Elasticsearch 集群的稳定 介绍 如何在大业务量下保持 Elasticsearch 集群的稳定? 内容 当我们使用 Elasticsearch ...
- Beta 冲刺 三
团队成员 051601135 岳冠宇 031602629 刘意晗 031602248 郑智文 031602330 苏芳锃 031602234 王淇 照片 项目进展 岳冠宇 ## 项目进展 昨天的困难 ...