Hdu1828 Picture
Picture
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5516 Accepted Submission(s): 2636
Write a program to calculate the perimeter. An example with 7 rectangles is shown in Figure 1.

The corresponding boundary is the whole set of line segments drawn in Figure 2.

The vertices of all rectangles have integer coordinates.
0 <= number of rectangles < 5000
All coordinates are in the range [-10000,10000] and any existing rectangle has a positive area.
Please process to the end of file.
-15 0 5 10
-5 8 20 25
15 -4 24 14
0 -6 16 4
2 15 10 22
30 10 36 20
34 0 40 16
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int maxn = , inf = 0x7ffffff;
int n, ans, cnt, minn = inf, maxx = -inf, tot;
int L[maxn << ], R[maxn << ], c[maxn << ], lc[maxn << ], rc[maxn << ], num[maxn << ], tag[maxn << ]; struct node
{
int l, r, h, id;
}e[maxn * ]; void build(int o, int l, int r)
{
L[o] = l;
R[o] = r;
num[o] = ;
lc[o] = rc[o] = ;
c[o] = ;
if (l == r)
return;
int mid = (l + r) >> ;
build(o * , l, mid);
build(o * + , mid + , r);
} bool cmp(node a, node b)
{
return a.h < b.h;
} void pushup(int o)
{
int l = L[o], r = R[o];
if (tag[o])
{
c[o] = r - l + ;
lc[o] = rc[o] = ;
num[o] = ;
}
else
if (l == r)
{
c[o] = ;
num[o] = ;
lc[o] = rc[o] = ;
}
else
{
c[o] = c[o * ] + c[o * + ];
lc[o] = lc[o * ];
rc[o] = rc[o * + ];
num[o] = num[o * ] + num[o * + ] - (rc[o * ] & lc[o * + ]);
}
} void update(int o, int x, int y, int v)
{
int l = L[o], r = R[o];
if (x <= l && r <= y)
{
tag[o] += v;
pushup(o);
return;
}
int mid = (l + r) >> ;
if (x <= mid)
update(o * , x, y, v);
if (y > mid)
update(o * + , x, y, v);
pushup(o);
} int main()
{
while (scanf("%d", &n) != EOF)
{
if (n == )
{
printf("%d\n", );
continue;
}
tot = ans = cnt = ;
minn = inf;
maxx = -inf;
memset(c, , sizeof(c));
memset(num, , sizeof(num));
memset(tag, , sizeof(tag));
memset(lc, , sizeof(lc));
memset(rc, , sizeof(rc));
memset(L, , sizeof(L));
memset(R, , sizeof(R));
for (int i = ; i <= n; i++)
{
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
minn = min(a, minn);
maxx = max(c, maxx);
e[++tot].l = a;
e[tot].r = c;
e[tot].h = b;
e[tot].id = ;
e[++tot].l = a;
e[tot].r = c;
e[tot].h = d;
e[tot].id = -;
}
sort(e + , e + + tot, cmp);
build(, minn, maxx - );
int last = ;
e[tot + ].h = e[tot].h;
for (int i = ; i <= tot; i++)
{
update(, e[i].l, e[i].r - , e[i].id);
ans += abs(c[] - last);
ans += (e[i + ].h - e[i].h) * num[] * ;
last = c[];
}
printf("%d\n", ans);
} return ;
}
Hdu1828 Picture的更多相关文章
- HDU1828 Picture 线段树+扫描线模板题
Picture Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU-1828 Picture(扫描线)
题目大意:给若干个矩形,求轮廓边长. 题目分析:与求面积类似.按从下往上扫描,仍然是底边添加,上边删除.但要同时维护竖边的数目,每次扫描对答案的贡献为扫描线上总覆盖长度的变化量加上竖边的增量.总覆盖长 ...
- HDU-1828 Picture(扫描线 求矩形并的周长)
http://acm.hdu.edu.cn/showproblem.php?pid=1828 Time Limit: 6000/2000 MS (Java/Others) Memory Limi ...
- hdu1828 Picture(线段树+扫描线+矩形周长)
看这篇博客前可以看一下扫描线求面积:线段树扫描线(一.Atlantis HDU - 1542(覆盖面积) 二.覆盖的面积 HDU - 1255(重叠两次的面积)) 解法一·:两次扫描线 如图我们可以 ...
- 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
- [转载]完全版线段树 by notonlysuccess大牛
原文出处:http://www.notonlysuccess.com/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...
- 【转】线段树完全版~by NotOnlySuccess
线段树完全版 ~by NotOnlySuccess 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章了,觉 ...
- 《完全版线段树》——notonlysuccess
转载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文 ...
- 【转】 线段树完全版 ~by NotOnlySuccess
载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章 ...
随机推荐
- 如何使用Win+R快捷键打开自定义程序
鉴于大家对于提高效率这块有争议,更改了下标题. 大家平时一定都使用过Win+R运行快捷键, 在运行里可以快捷的打开一些系统软件,比如说输入mstsc是打开远程连接,输入explorer是打开文件管理器 ...
- smartgit 过期
进入到安装目录把Setting.xml 文件删除然后,再次打开就可以正常使用了.
- 修改Linux系统下的最大文件描述符限制
通常我们通过终端连接到linux系统后执行ulimit -n 命令可以看到本次登录的session其文件描述符的限制,如下: $ulimit -n1024 当然可以通过ulimit -SHn 1024 ...
- Python学习小目录汇总
python其他知识目录 python基础知识-1 1.typora软件使用 2.python解释器安装 3.Python解释器环境变量添加 4.计算机编码知识: 5.输出print(): 6.变量 ...
- ES6的新特性(10)——Class 的基本语法
Class 的基本语法 简介 JavaScript 语言中,生成实例对象的传统方法是通过构造函数.下面是一个例子. function Point(x, y) { this.x = x; this.y ...
- mysql---时间类型详解
mysql 日期类型 mysql 日期类型 · DATE (适用于"出生日期"等只需要年月日数据的日期字段) 日期.支持的范围为'1000-01-01'到'9999-12- ...
- Spring学习(七)——增强类
Spring 切点 什么是切点?切点(Pointcut),每个程序类都拥有多个连接点,如一个拥有两个方法的类,这两个方法都是连接点,即连接点是程序类中客观存在的事物.但在这为数从多的连接点中,如何定位 ...
- SpringBoot与Swagger2整合
一.Swagger简介与优势 相信各位在公司写API文档数量应该不少,当然如果你还处在自己一个人开发前后台的年代,当我没说,如今为了前后台更好的对接,还为了以后交接方便,都有要求写API文档. Swa ...
- Tomcat指定JDK路径
一.应用实例 一般情况下一台服务器只跑一个业务,那么就直接配置一套环境,设置好Java环境变量即可.某些时候一台服务器上会安装多个业务,而且各个业务需要的JDK版本各不相同,或者为了使业务独立开来,需 ...
- 剖析Vue原理&实现双向绑定MVVM-2
vue.js 最核心的功能有两个,一是响应式的数据绑定系统,二是组件系统.本文仅探究双向绑定是怎样实现的.先讲涉及的知识点,再用简化得不能再简化的代码实现一个简单的 hello world 示例. 一 ...