只需要倒着插入,然后维护一个凸包就可以了。

可以用来学习set的用法

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i)
#define inf 100000
#define ll long long
#define mp make_pair
#define sqr(x) x*x int n,x,y,m,k;
struct Vector{
double x,y;
void print(){printf("Vector (%.3f,%.3f)\n",x,y);}
}; struct Point{
int x,y;
void print(){printf("Point (%d,%d)\n",x,y);}
bool operator < (const Point b) const{
return x==b.x?y<b.y:x<b.x;
}
}a[200005]; set <Point> s; struct Options{int opt,id;}q[200005]; double dist (Point a,Point b)
{
// printf("dist\n");
// a.print();b.print();
// printf("The ans is %.6f\n",sqr((double)a.x-b.x)+sqr((double)a.y-b.y));
return sqrt(((double)a.x-b.x)*((double)a.x-b.x)+((double)a.y-b.y)*((double)a.y-b.y));
} Vector operator - (Point a,Point b)
{Vector ret;ret.x=a.x-b.x;ret.y=a.y-b.y;return ret;} double operator * (Vector a,Vector b)
{
// a.print(); printf("* * *\n");
// b.print();
// printf("= %.6f\n",a.x*b.y-a.y*b.x);
return a.x*b.y-a.y*b.x;
} int tot,del[200005];
double ans[200005],now;
Point newnode; void init()
{
now=n*1.0;
newnode.x=0;newnode.y=0;
s.insert(newnode);
// newnode.x=0;newnode.y=-inf;
// s.insert(newnode);
newnode.x=n;newnode.y=0;
s.insert(newnode);
// newnode.x=n;newnode.y=-inf;
// s.insert(newnode);
// printf("now is %.6f\n",now);
} void add(Point x)
{
// printf("Add "); x.print();
set<Point>::iterator it,iL,iR;
it=s.lower_bound(x);
iL=it;iL--;iR=it;
if ((x-*iL)*(*iR-x)>0) return;
// printf("New node\n");
now-=dist(*iL,*iR);
for (;;)
{
iR=it;it++;
if (it==s.end()) break;
if ((*iR-x)*(*it-x)>0)
{
now-=dist(*iR,*it);
s.erase(*iR);
// printf("del R\n"); while (1);
}
else break;
}
for (;;)
{
if (iL==s.begin()) break;
Point L=*iL; iL--;
// (*iL-*it).print();
// (*it-x).print();
if ((L-*iL)*(x-*iL)>0)
{
now-=dist(*iL,L);
s.erase(L);
// printf("del L\n"); //while(1);
}
else break;
}
s.insert(x);
it=s.find(x);
iL=it;iL--;iR=it;iR++;
now+=dist(*iL,x)+dist(x,*iR);
// printf("now is %.6f\n",now);
return ;
} void Finout()
{
freopen("defense.in","r",stdin);
freopen("defense.out","w",stdout);
} int main()
{
// freopen("in.txt","r",stdin);
scanf("%d%d%d",&n,&x,&y);
scanf("%d",&m);
F(i,1,m) scanf("%d%d",&a[i].x,&a[i].y);
scanf("%d",&k);
// printf("k is %d\n",k);
F(i,1,k)
{
scanf("%d",&q[i].opt);
switch(q[i].opt)
{
case 1:scanf("%d",&q[i].id); del[q[i].id]=1;break;
case 2:q[i].id=++tot; break;
}
}
// F(i,1,k) printf("Opt %d id %d\n",q[i].opt,q[i].id);
init(); newnode.x=x;newnode.y=y;add(newnode);
F(i,1,m) if (!del[i]) add(a[i]);
D(i,k,1)
{
switch(q[i].opt)
{
case 1:add(a[q[i].id]);break;
case 2:ans[q[i].id]=now;break;
}
}
F(i,1,tot) printf("%.2f\n",ans[i]);
}

  

BZOJ 2300 [HAOI2011]防线修建 ——计算几何的更多相关文章

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

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

  2. bzoj 2300: [HAOI2011]防线修建 凸包

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=2300 题解 这道题让我们维护一个支持动态删除点的上凸壳 并且告诉了我们三个一定不会被删除 ...

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

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

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

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

  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. 【题解】P2521 [HAOI2011]防线修建(动态凸包)

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

  9. [luogu P2521] [HAOI2011]防线修建

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

随机推荐

  1. Ubuntu安装新英伟达驱动出现问题解决方法

    ERROR: The Nouveau kernel driver is currently in use by your system. This driver is incompatible wit ...

  2. uvm_base——打好你的基础

    uvm_base 是个很有意思的文件,这是UVM很巧妙的设计,将所有在base中包含的文件都包含在uvm_base.svh, 这样很方便管理各个文件直接的关系,而且还可以看出一些我之前没看过的东西,比 ...

  3. IOSAutolayout

    21:55:33前言 1 MagicNumber -> autoresizingMask -> autolayout 以上是纯手写代码所经历的关于页面布局的三个时期 在iphone1-ip ...

  4. Windows系统下如何优化Android Studio

    Android Studio将是Android开发大势所趋. 安装Android Studio时需注意的细节: · 找到安装目录bin目录下idea.properties 最后一行加入:    dis ...

  5. POJ 3133 Manhattan Wiring (插头DP,轮廓线,经典)

    题意:给一个n*m的矩阵,每个格子中有1个数,可能是0或2或3,出现2的格子数为2个,出现3的格子数为2个,要求将两个2相连,两个3相连,求不交叉的最短路(起终点只算0.5长,其他算1). 思路: 这 ...

  6. Java异常处理:如何写出“正确”但被编译器认为有语法错误的程序

    文章的标题看似自相矛盾,然而我在"正确"二字上打了引号.我们来看一个例子,关于Java异常处理(Exception Handling)的一些知识点. 看下面这段程序.方法pleas ...

  7. 原生js格式化json的方法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. CentOS7——防火墙设置

    1.查看firewall服务状态 systemctl status firewalld 2.查看firewall的状态firewall-cmd --state 3.开启.重启.关闭.firewalld ...

  9. CAD交互绘制批注(网页版)

    js中实现代码说明: 动态拖放时的绘制事件: function DynWorldDrawComment( pCustomEntity, pWorldDraw, curPt) { // 得到绘制参数. ...

  10. Spring对注解(Annotation)处理【转】

    1.从Spring2.0以后的版本中,spring也引入了基于注解(Annotation)方式的配置,注解(Annotation)是JDK1.5中引入的一个新特性,用于简化Bean的配置,某些场合可以 ...