P2521 [HAOI2011]防线修建
题目链接:P2521 [HAOI2011]防线修建
题意:给定点集
每次有两种操作:
1. 删除一个点 (除开(0, 0), (n, 0), 与指定首都(x, y))
2. 询问上凸包长度
至于为什么是上凸包 “三角形任意两边之和大于第三边”就可以证
我们的套路不包括只做删除的在线凸包问题 所以把询问逆序操作
根据套路 只有插入操作的 对答案贡献不独立的凸包问题 我们使用平衡树维护
其实只用求前驱后继 所以蒟蒻就偷懒用了STL的set
一开始构造最后删完的点集的凸包
每次插入一个点时
如果它在当前凸包内部或凸包上 那么不影响答案 直接忽略
如果在外部 从近到远询问它前面的点 类似于Andrew一开始插入点的做法
再从近到远询问它后面的点 做法同样
记得维护答案
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
using namespace std;
const int N = 1e5 + ;
const int Q = 2e5 + ;
const double eps = 1e-;
struct Node{
int id;
double x, y;
}node[N], stk[N], nl;
set<Node> st;
int rf[N];
struct Query{
int x, y;
}q[Q];
double anss[N];
int as;
int n, m, cx, cy, qs;
int top;
double ans;
bool ask[N]; Node operator - (const Node& x, const Node& y){
return (Node){, x.x - y.x, x.y - y.y};
} bool operator < (const Node& x, const Node& y){
if(fabs(x.x - y.x) < eps) return x.y + eps < y.y;
return x.x + eps < y.x;
} inline double cross(Node x, Node y){
return x.x * y.y - x.y * y.x;
} inline double dis(Node x, Node y){
return sqrt((y.x - x.x) * (y.x - x.x)
+ (y.y - x.y) * (y.y - x.y));
} Node next(Node x){
set<Node> :: iterator it;
it = st.upper_bound(x);
if(it != st.end()) return *it;
else return nl;
} Node prev(Node x){
set<Node> :: iterator it;
it = st.lower_bound(x);
if(it != st.begin()) return *(--it);
else return nl;
} inline void Andrew(){
top = ;
for(int i = ; i <= m; i++) if(!ask[node[i].id]){
while(top > && cross(stk[top] - stk[top - ], node[i] - stk[top]) > eps){
ans -= dis(stk[top], stk[top - ]);
top--;
}
stk[++top] = node[i];
if(top > ) ans += dis(stk[top], stk[top - ]);
}
for(int i = ; i <= top; i++)
st.insert(stk[i]);
} inline void init(){
scanf("%d%d%d%d", &n, &cx, &cy, &m);
for(int i = ; i <= m; i++){
scanf("%lf%lf", &node[i].x, &node[i].y);
node[i].id = i;
}
++m; node[m] = (Node){m, , };
++m; node[m] = (Node){m, 1.0 * n, };
++m; node[m] = (Node){m, 1.0 * cx, 1.0 * cy};
sort(node + , node + m + );
for(int i = ; i <= m; i++){
rf[node[i].id] = i;
}
scanf("%d", &qs);
for(int i = ; i <= qs; i++){
scanf("%d", &q[i].x);
if(q[i].x == ){
scanf("%d", &q[i].y);
ask[q[i].y] = ;
}
else {
as++;
q[i].y = as;
}
}
Andrew();
} inline void ins(Node x){
Node pre = prev(x), pp;
Node nxt = next(x), nn;
if(cross(x - pre, nxt - x) > eps){
return ;
}
ans -= dis(pre, nxt);
while(pre.id != m - ){
pp = prev(pre);
if(cross(pre - pp, x - pre) > eps){
ans -= dis(pp, pre);
st.erase(pre);
pre = pp;
}
else break;
}
ans += dis(pre, x);
while(nxt.id != m - ){
nn = next(nxt);
if(cross(nxt - x, nn - nxt) > eps){
ans -= dis(nxt, nn);
st.erase(nxt);
nxt = nn;
}
else break;
}
ans += dis(x, nxt);
st.insert(x);
} int main(){
init();
for(int i = qs; i >= ; i--)
if(q[i].x == )
ins(node[rf[q[i].y]]);
else
anss[q[i].y] = ans;
for(int i = ; i <= as; i++) printf("%.2lf\n", anss[i]);
return ;
}
附上代码:
P2521 [HAOI2011]防线修建的更多相关文章
- [luogu P2521] [HAOI2011]防线修建
[luogu P2521] [HAOI2011]防线修建 题目描述 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国 ...
- 【题解】P2521 [HAOI2011]防线修建(动态凸包)
[题解]P2521 [HAOI2011]防线修建(动态凸包) 凸包是易插入不好删除的东西,按照剧情所以我们时光倒流 然后问题就是维护凸包的周长,支持加入 本来很简单,但是计算几何就是一些小地方经验不足 ...
- Bzoj2300 / 洛谷P2521 [HAOI2011]防线修建
题目描述 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上层现在还犹豫不决,到底该把哪些城市作为保护对象呢?又由于 ...
- 【BZOJ 2300】 2300: [HAOI2011]防线修建 (动态凸包+set)
2300: [HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上 ...
- BZOJ 2300: [HAOI2011]防线修建( 动态凸包 )
离线然后倒着做就变成了支持加点的动态凸包...用平衡树维护上凸壳...时间复杂度O(NlogN) --------------------------------------------------- ...
- bzoj千题计划236:bzoj2300: [HAOI2011]防线修建
http://www.lydsy.com/JudgeOnline/problem.php?id=2300 维护动态凸包,人懒用的set 用叉积判断,不要用斜率 #include<set> ...
- 【BZOJ2300】[HAOI2011]防线修建 set维护凸包
[BZOJ2300][HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可 ...
- 【bzoj2300】【Luogu P2521】 [HAOI2011]防线修建 动态凸包,平衡树,Set
一句话题意:给你一个凸包,每次可以插入一个点或者询问周长. 动态凸包裸题嘛,用\(Set\)实现.最初每个点坐标做乘三处理,便于取初始三角形的重心作为凸包判定原点. #include <bits ...
- BZOJ2300[HAOI2011]防线修建——非旋转treap+凸包(平衡树动态维护凸包)
题目描述 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上层现在还犹豫不决,到底该把哪些城市作为保护对象呢?又由于 ...
随机推荐
- SoftWater——SDN+UnderWater系列论文一
---- SoftWater: Software-defined networking for next-generation underwater communication systems 来源: ...
- C#跨进程读取listview控件中的数据
http://www.cnblogs.com/Charltsing/p/slv32.html 欢迎交流:QQ564955427 读取标准的32位listview控件中的数据,网上已经有很多代码了.今天 ...
- rest-framework的认证组件
认证组件 1.登录认证(与组件无关): 首先要在model表内添加用户表和token表: from django.db import models # Create your models here. ...
- Django组件之认证系统
Django自带的用户认证 我们在开发一个网站的时候,无可避免的需要设计实现网站的用户系统.此时我们需要实现包括用户注册.用户登录.用户认证.注销.修改密码等功能,这还真是个麻烦的事情呢. Dja ...
- 【翻译】asp.net core2.1认证和授权解密
asp.net core2.1认证和授权解密 本篇文章翻译自:https://digitalmccullough.com/posts/aspnetcore-auth-system-demystifie ...
- [转帖]SAP一句话入门:Material Management
SAP一句话入门:Material Management http://blog.vsharing.com/MilesForce/A616683.html 让我们来关注供应链上的另一个模块Materi ...
- Day 4-4 shutil模块
常用方法: import shutil f = open("conf.ini", "r") f1 = open("shutil.ini", ...
- C# Note32: 查漏补缺
(1)Using的三种使用方式 (2)C#详解值类型和引用类型区别 (3)c#中字段(field)和属性(property)的区别 (4)C#中的 int? int?:表示可空类型,就是一种特殊的值类 ...
- postgreSQL使用杂谈
由于当时是在美国安装的postgreSQL ,导致回到上海后使用时,发现时间数据显示不正确. To acomplish the timezone change in Postgres 9.6 you ...
- python3文字转语音
#安装库(必须先安装pywin32) pip3 install pyttsx3 简单测试 import pyttsx3 engine = pyttsx3.init() text='name' engi ...