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国 ...
随机推荐
- 项目在cocos 2.23移植到cocos 3.1.0所出现的bug
在建项目时一定要注意选择源代码!而不是预编译库 "extensions/ExtensionMacros.h”: No such file 项目右键-属性-配置属性-c/c++ - 常规-附加 ...
- uvm_reg_item——寄存器模型(五)
uvm_reg_item 扩展自uvm_sequence_item,也就说寄存器模型定义了transaction item. adapter 的作用是把这uvm_reg_item转换成uvm_sequ ...
- IOS拉伸之底盖设置
1.选定拉伸 UIImageView *fieldImage=[[UIImageViewalloc]initWithFrame:CGRectMake(37,48+35,240, 32)]; field ...
- POJ 2449 Remmarguts' Date
Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30725 Accepted: 8389 Description &quo ...
- Python相关机器学习
Python机器学习库 Python的机器学习库汇总与梳理 机器学习之开源库大总结
- Spring MVC能响应HTTP请求的原因?
很多Java面试官喜欢问这个问题: 一个Spring MVC的项目文件里,开发人员没有开发自己的Servlet,只通过注解@RequestMapping定义了方法home能响应发向 /mvc/test ...
- Python-OpenCV:cv2.imread(),cv2.imshow(),cv2.imwrite()
为什么使用Python-OpenCV? 虽然python 很强大,而且也有自己的图像处理库PIL,但是相对于OpenCV 来讲,它还是弱小很多.跟很多开源软件一样OpenCV 也提供了完善的pytho ...
- 换个语言学一下 Golang (5)——运算符
运算符用于在程序运行时执行数学或逻辑运算. Go 语言内置的运算符有: 算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 其他运算符 接下来让我们来详细看看各个运算符的介绍. 算术运算符 下表 ...
- python爬虫---实现项目(四) 用BeautifulSoup分析新浪新闻数据
这次只演示了,如何在真实项目内用到BeautifulSoup库来解析网页,而新浪的新闻是ajax加载过来的数据,在这里我们只演示解析部分数据(具体反扒机制没做分析). 代码地址:https://git ...
- webuploader项目中多图片上传实例
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...