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的子节点 那么 ...
随机推荐
- 【ORACLE】碎片整理
alter table test enable row movement; alter table test shrink space; execute dbms_stats.gather_table ...
- Mysql_临时表
CREATE TEMPORARY TABLE test_info ( test_name ) NOT NULL, test_totail ,) NOT NULL DEFAULT 0.00, test_ ...
- iOS开发面试题整理
前言 本文借鉴整理了iOS高级开发常见的面试题,并且分博客一一分析,希望能和大家一起进步学习. 欢迎大家关注我的 Github
- 290. Word Pattern【LeetCode by java】
今天发现LintCode页面刷新不出来了,所以就转战LeetCode.还是像以前一样,做题顺序:难度从低到高,每天至少一题. Given a pattern and a string str, fin ...
- MySQL数据库--外键约束及外键使用
什么是主键.外键关系型数据库中的一条记录中有若干个属性,若其中某一个属性组(注意是组)能唯一标识一条记录,该属性组就可以成为一个主键. 比如: 学生表(学号,姓名,性别,班级) 其中每个学生的学号是唯 ...
- error: Build input file cannot be found: '*******/node_modules/react-native/Libraries/WebSocket/libfishhook.a' 问题解决记录
解决了刚才的'config.h' file not found问题,本以为就可以顺畅的跑起来,谁知道又被恶心到了,Build input file cannot be found!!! 问题: err ...
- 11.7 Daily Scrum(周末暂停两天Daily Scrum)
由于APEC放假,有些成员离校了,他们那部分的任务会暂时拖后一些,之后会加班加点赶工. 另外,每个人的任务还是相对独立,离校成员的任务进度不会对其他成员的进度造成很大影响. Today's tas ...
- 第一次scrum meeting
在这次会议中,我们确定了任务的具体分配.这里截取一部分,每个人都有20个小时左右的编程任务,整个项目共计约140小时. 明天是正式开始软件实现的第一天,下面列出前两天每个人的任务: 第一天 第二天 ...
- C++的OOP特性
内存模型和名称空间 存储持续性,作用域和链接性 C++有三种方案来存储数据 自动存储持续性:在函数定义中声明的变量,包括函数参数.在函数或代码块开始执行时创建.执行完函数或者代码块,内存自动释放. 静 ...
- 【助教】浅析log4j的使用
有不少童鞋私信我一些在写代码时候遇到的问题,但是无法定位问题出在哪里,也没有日志记录,实际上,写日志是开发项目过程中很重要的一个环节,很多问题都可以从日志中找到根源,从而定位到出错位置,为解决问题提供 ...