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

可以用来学习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. bin&sbin 命令作用

    最近需要了解sbin与bin的功能,需要整理一下.一下全部为Ubuntu14里面默认安装的.在这里收集一下,转载请注明出处! bin bash shell bunzip2 .bz2文件的解压缩程序. ...

  2. 解决 FusionCharts3.2.1 首页无法载入的问题

    在实际项目中测试FusionCharts3.2.1时,发现首次载入无法正常载入,第二次载入就恢复正常!   原因:FusionCharts ID与变量名重复   以下是正常写法: var member ...

  3. Redis性能优化之redis.cnf配置参数

    redis调优总结 1.相应的参数调优 加内存2.redis使用结构调优3.使用合理的数据类型说明:redis存储的数据为redis hash(字符映射表) 单key多字段结构. 1)调整配置文件中配 ...

  4. MySQL字符集和排序介绍

    客服端字符集: character_set_client utf8mb4连接字符集: character_set_connection utf8mb4数据库字符集: character_set_dat ...

  5. springMVC中ajax和后台数据格式错误

    前台ajax: $.ajax("${pageContext.request.contextPath}/hello",// 发送请求的URL字符串. { dataType : &qu ...

  6. easyui 刷新页面

    window.location.reload()刷新当前页面. parent.location.reload()刷新父亲对象(用于框架) opener.location.reload()刷新父窗口对象 ...

  7. C程序(2)

     

  8. 洛谷 p1141 01迷宫题解

    很长时间没发博客了,今天水一下 很多dalao说染色(普通的)过不了, 我怎么就过了 其实我也是今天才知道什么是染色(由@你听风在吼 dalao指导) 然后自己打了一个,也不知道叫不叫染色,反正是过了 ...

  9. mysql 复制中的 paxso 的两阶段和事务两阶段的区别

    1.普通的两阶段是 推送不同的数据给不同的主机,一旦出现网络中断,造成问题是不可服务. 因为本身有锁,故无所谓. 2.paxos 的两阶段是将相同的 数据给不同的主机,一旦超过半数即可认为成功.

  10. 同时使用多个UITableView

    1.xib\storyboard中给2个tableView设置constraints(等宽) 方法 : ①设置mainTableView的上\下\左\三部分的约束为0:subTableView上\下\ ...