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的子节点 那么 ...
随机推荐
- spring boot 实现文件下载
html 代码 js部分 window.location.href= this.Baseurl+'/plan/down?file='+filename; spring boot 后台代码@GetMap ...
- EditText点击出现光标但不弹出软键盘
3.0以下版本可以用editText.setInputType(InputType.TYPE_NULL)来实现.或者设置editText.setKeyListener(null)来实现. 3.0以上版 ...
- unity纯粹物理驱动方式
首先见官方文档 In most cases you should not modify the velocity directly, as this can result in unrealistic ...
- 在WebGL场景中建立游戏规则
在前三篇文章的基础上,为基于Babylon.js的WebGL场景添加了类似战棋游戏的基本操作流程,包括从手中选择单位放入棋盘.显示单位具有的技能.选择技能.不同单位通过技能进行交互.处理交互结果以及进 ...
- 20135327郭皓--Linux内核分析第五周 扒开系统调用的三层皮(下)
Linux内核分析第五周 扒开系统调用的三层皮(下) 郭皓 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.com/course/U ...
- VS2013简单的单元测试
安装过程本人在此就不做多余的说明,如果一个程序员连一个软件都无法安装那我也醉了,其次就是希望我们不要为了完成作业而去用VS,下面我具体说一下单元测试. 第一步,文件→新建一个项目,具体操作如下图 打开 ...
- 功能WBS分解
小组名称:飞天小女警 项目名称:礼物挑选小工具 小组成员:沈柏杉(组长).程媛媛.杨钰宁.谭力铭 代码地址:HTTPS: https://git.coding.net/shenbaishan/GIFT ...
- OneZero第二次站立会议(2016.3.22)
会议时间:2016年3月22日 9:33~9:57 会议成员:冉华,张敏,王巍,夏一鸣. 会议目的:汇报前一天工作,全体成员评论并修改. 会议内容:以下为会议插图 1.界面原型方面,小组成员对夏所画的 ...
- 【设计模式】—— 享元模式Flyweight
前言:[模式总览]——————————by xingoo 模式意图 享元模式,也叫[轻量级模式]或者[蝇量级模式].主要目的就是为了减少细粒度资源的消耗.比如,一个编辑器用到大量的字母数字和符号,但是 ...
- Java学习之静态代码块
一.static(在方法区有一块固定的存储区域,由于优先于对象存在,所以可以被所有对象共享) 在定义方法的时候你写main方法的类加static, 写普通类的写方法的时候就不要加static 1.st ...