BZOJ 2300 [HAOI2011]防线修建 ——计算几何
只需要倒着插入,然后维护一个凸包就可以了。
可以用来学习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]防线修建 ——计算几何的更多相关文章
- BZOJ 2300: [HAOI2011]防线修建( 动态凸包 )
离线然后倒着做就变成了支持加点的动态凸包...用平衡树维护上凸壳...时间复杂度O(NlogN) --------------------------------------------------- ...
- bzoj 2300: [HAOI2011]防线修建 凸包
题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=2300 题解 这道题让我们维护一个支持动态删除点的上凸壳 并且告诉了我们三个一定不会被删除 ...
- bzoj 2300 : [HAOI2011]防线修建
set动态维护凸包 #include<iostream> #include<cstdio> #include<cstring> #include<algori ...
- bzoj 2300 [HAOI2011]防线修建 set动态维护凸包
题目大意 动态删点,求凸包周长 分析 反过来变成动态加点 用set维护平衡树 具体是找到凸包上左右两点 拆开 就可以把左边当作顺时针求的一个凸包,右边当作逆时针求的一个凸包,像栈那样出set就好了 注 ...
- 【BZOJ 2300】 2300: [HAOI2011]防线修建 (动态凸包+set)
2300: [HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上 ...
- bzoj2300#2300. [HAOI2011]防线修建
题解:带删点的维护凸包,1.删点2.查询凸包周长 题解:倒着做就成了带加点的维护凸包,加点时维护一下周长就没了 //#pragma GCC optimize(2) //#pragma GCC opti ...
- bzoj千题计划236:bzoj2300: [HAOI2011]防线修建
http://www.lydsy.com/JudgeOnline/problem.php?id=2300 维护动态凸包,人懒用的set 用叉积判断,不要用斜率 #include<set> ...
- 【题解】P2521 [HAOI2011]防线修建(动态凸包)
[题解]P2521 [HAOI2011]防线修建(动态凸包) 凸包是易插入不好删除的东西,按照剧情所以我们时光倒流 然后问题就是维护凸包的周长,支持加入 本来很简单,但是计算几何就是一些小地方经验不足 ...
- [luogu P2521] [HAOI2011]防线修建
[luogu P2521] [HAOI2011]防线修建 题目描述 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国 ...
随机推荐
- mongodb-3.2.8 单机复制集安装
规划: replSet 复制集名称: rs1 MongoDB数据库安装安装路径为:/usr/local/mongodb/ 复制集成员IP与端口: 节点1: localhost:28010 (默认的 ...
- mongo ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
解决方法 rm /var/lib/mongodb/mongod.lock
- Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Reason: Failed to determine a suitable driver class
解决方案: @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) 作用://取消数据库配置 但是 在用到数据库的时候记 ...
- js 判断是什么浏览器、是否为谷歌浏览器
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http ...
- 如何实现第二窗口不显示在windows下面的任务栏中
将要隐藏的窗体的的ShowInTaskBar属性设置为false;就好了
- Socket通讯简易学习
Socket打开通信通道,告诉本地机器,愿意在该通道上接受客户请求——监听,等待客户请求——接受请求,创建专用链接进行读写——处理完毕,关闭专用链接——关闭通信通道(当然其中监听到关闭专用链接可以重复 ...
- Java数据结构和算法(五)--希尔排序和快速排序
在前面复习了三个简单排序Java数据结构和算法(三)--三大排序--冒泡.选择.插入排序,属于算法的基础,但是效率是偏低的,所以现在 学习高级排序 插入排序存在的问题: 插入排序在逻辑把数据分为两部分 ...
- 理解 React,但不理解 Redux,该如何通俗易懂的理解 Redux?(转)
作者:Wang Namelos 链接:https://www.zhihu.com/question/41312576/answer/90782136来源:知乎 解答这个问题并不困难:唯一的要求是你熟悉 ...
- TryEnterCriticalSection
if (TryEnterCriticalSection(&g_cs) == FALSE) { 返回 } else { 进入临界区 LeaveCriticalSection(&g_cs) ...
- 毛毛虫组【Beta】Scrum Meeting 3
第三天 日期:2019/6/25 前言 第三次会议: 时间:6月25日 地点:教10-A511 内容:此次会议主要是对项目验收做准备工作. 1.1 今日完成任务情况以及遇到的问题. 今日完成任务情况: ...