题目大意:

http://www.lydsy.com/JudgeOnline/problem.php?id=2300

题解

这道题让我们维护一个支持动态删除点的上凸壳

并且告诉了我们三个一定不会被删除的点

也就是说,无论什么时候这都是一个凸包

如果我们考虑从凸包里删除一个点吗...这个点在凸包里还好说,不用管了

在凸包上嘛...哪位dalao写出来了请教教我,并不会删除QAQ

所以我们倒序考虑所有的操作,将其变成动态插入点

每一次插入一个点的时候,我们找到凸包上与这个点关联的两个点

(按照横纵坐标进行双关键字排序后与之相邻的两个点)

我们就从这两个点开始依次向左右拓展,并且即时更新凸包的长度

所以我们用set存一下所有在凸包上的点即可

#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 100010;
const int maxm = 200010;
struct Point{
int x,y;
Point(const int &a = 0,const int &b = 0){x=a;y=b;}
void print(){
printf("Point : (%d,%d)\n",x,y);
}
};
typedef Point Vector;
Vector operator + (const Vector &a,const Vector &b){
return Vector(a.x+b.x,a.y+b.y);
}
Vector operator - (const Vector &a,const Vector &b){
return Vector(a.x-b.x,a.y-b.y);
}
bool operator < (const Point &a,const Point &b){
return a.x == b.x ? a.y < b.y : a.x < b.x;
}
int operator * (const Vector &a,const Vector &b){
return a.x*b.x + a.y*b.y;
}
inline int cross(const Vector &a,const Vector &b){
return a.x*b.y - a.y*b.x;
}
inline double sqr(const double &x){
return x*x;
}
inline double dis(Point a,Point b){
return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}
struct Node{
int cmd,x;
}quer[maxm];
set<Point>s;
Point p[maxn];bool vis[maxn];
double ans = .0;
double anss[maxm];int cnt;
void insert(Point x){
set<Point>::iterator r = s.lower_bound(x);
set<Point>::iterator l = --r;r++;
set<Point>::iterator it;
if(cross(x - *l,*r - *l) >= 0) return;
ans -= dis(*l,*r);
while(1){
it = r++;
if(r == s.end()) break;
if(cross(*r - *it,*it - x) > 0) break;
ans -= dis(*it,*r);s.erase(it);
}
ans += dis(x,*it);
while(1){
it = l--;
if(it == s.begin()) break;
if(cross(x - *it,*it - *l) > 0) break;
ans -= dis(*it,*l);s.erase(it);
}
ans += dis(x,*(it));
s.insert(x);
}
int main(){
int n,x,y;read(n);read(x);read(y);
s.insert(Point(0,0));
s.insert(Point(x,y));
s.insert(Point(n,0));
ans += dis(Point(0,0),Point(x,y)) + dis(Point(x,y),Point(n,0));
read(n);
for(int i=1;i<=n;++i){
read(p[i].x);
read(p[i].y);
}
int m;read(m);
for(int i=1;i<=m;++i){
read(quer[i].cmd);
if(quer[i].cmd == 1){
read(quer[i].x);
vis[quer[i].x] = true;
}
}
for(int i=1;i<=n;++i){
if(!vis[i]) insert(p[i]);
}
for(int i=m;i>=1;--i){
if(quer[i].cmd == 1) insert(p[quer[i].x]);
else anss[++cnt] = ans;
}
for(int i=cnt;i>=1;--i) printf("%.2lf\n",anss[i]);
getchar();getchar();
return 0;
}

bzoj 2300: [HAOI2011]防线修建 凸包的更多相关文章

  1. BZOJ 2300: [HAOI2011]防线修建( 动态凸包 )

    离线然后倒着做就变成了支持加点的动态凸包...用平衡树维护上凸壳...时间复杂度O(NlogN) --------------------------------------------------- ...

  2. bzoj 2300 [HAOI2011]防线修建 set动态维护凸包

    题目大意 动态删点,求凸包周长 分析 反过来变成动态加点 用set维护平衡树 具体是找到凸包上左右两点 拆开 就可以把左边当作顺时针求的一个凸包,右边当作逆时针求的一个凸包,像栈那样出set就好了 注 ...

  3. bzoj 2300 : [HAOI2011]防线修建

    set动态维护凸包 #include<iostream> #include<cstdio> #include<cstring> #include<algori ...

  4. BZOJ 2300 [HAOI2011]防线修建 ——计算几何

    只需要倒着插入,然后维护一个凸包就可以了. 可以用来学习set的用法 #include <map> #include <set> #include <cmath> ...

  5. 【BZOJ 2300】 2300: [HAOI2011]防线修建 (动态凸包+set)

    2300: [HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上 ...

  6. bzoj2300#2300. [HAOI2011]防线修建

    题解:带删点的维护凸包,1.删点2.查询凸包周长 题解:倒着做就成了带加点的维护凸包,加点时维护一下周长就没了 //#pragma GCC optimize(2) //#pragma GCC opti ...

  7. bzoj千题计划236:bzoj2300: [HAOI2011]防线修建

    http://www.lydsy.com/JudgeOnline/problem.php?id=2300 维护动态凸包,人懒用的set 用叉积判断,不要用斜率 #include<set> ...

  8. 【BZOJ2300】[HAOI2011]防线修建 set维护凸包

    [BZOJ2300][HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可 ...

  9. 【题解】P2521 [HAOI2011]防线修建(动态凸包)

    [题解]P2521 [HAOI2011]防线修建(动态凸包) 凸包是易插入不好删除的东西,按照剧情所以我们时光倒流 然后问题就是维护凸包的周长,支持加入 本来很简单,但是计算几何就是一些小地方经验不足 ...

随机推荐

  1. 九度OJ 1339:ACM (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:712 解决:379 题目描述: 今年的ACM世界总决赛快要开始了,需要有一个排名算法来对每支队伍进行现场排名.ACM组委会把这个任务交给了你 ...

  2. bash编程基础

    bash变量 变量命名: 1.不能使用程序中的关键字(保留字) 2.只能使用数字.字母和下划线,且不能以数字开头 3.要见名知义 变量类型: 数值型:精确数值(整数),近似数值(浮点型) 字符型:ch ...

  3. [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException] The child node "db_driver" at path "fos_user" must be configured.

    $ php bin/console server:run [Symfony\Component\Config\Definition\Exception\InvalidConfigurationExce ...

  4. 搜索ABAP程序代码中的字符串

    标准程序名:RPR_ABAP_SOURCE_SCAN /BEV1/NERM07DOCS

  5. Python字典的入门案例

    查看python版本: [root@localhost ~]# python -V Python 2.7.5 1.基本的字典操作 案例1:简单电话本实现 [root@localhost ~]# vim ...

  6. mysql 自连接查询数据

    今天项目BOSS提了个sql语句需求,我听得稀里糊涂,没办法,一步步讨论.实践,最终搞定. 先上建表语句: /* Navicat MySQL Data Transfer Source Server : ...

  7. socket编程详解

    http://www.cnblogs.com/skynet/archive/2010/12/12/1903949.html http://blog.csdn.net/hguisu/article/de ...

  8. spring mvc实现Restful返回xml格式数据

    最近,想在自己的小项目中搭建一个Restful风格的服务接口api,项目用的spring mvc 3,听说spring mvc本身就能十分方便的支持restful的实现,于是查询了下资料,果然非常强大 ...

  9. 数据库连接理解——JDBC

    需求:数据库操作 数据是:用户信息 1.连接数据库  JDBC Hibernate 2.操作数据库 c create r read u update d delete 3.关闭数据库连接 interf ...

  10. [原创]java WEB学习笔记23:MVC案例完整实践(part 4)---模糊查询的设计与实现

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...