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打广告,但是现在我自己都不太好意思去看那篇文章 ...
随机推荐
- 在django中使用django_debug_toolbar
一.概述 django_debug_toolbar 是django的第三方工具包,给django扩展了调试功能. 包括查看执行的sql语句,db查询次数,request,headers,调试概览等. ...
- Debian 9 + Windows 10 双系统安装体验
很久之前就想在自己的电脑上也装个 Debian 玩玩了,最近正好有时间折腾,就踩了踩坑在笔记本上装了玩玩~ UEFI + GPT 解决启动相关的麻烦配置 如果在支持 UEFI 的电脑上安装 Debia ...
- leetcode个人题解——#56 Merge Intervals
思路,先按照结构体中start进行排序,然后遍历比较前后项是否有重合. 第一次用到三参数形式的sort(),第三个参数的bool函数要写到类外才通过. /** * Definition for an ...
- redis rdb aof比较
Redis中数据存储模式有2种:cache-only,persistence; cache-only即只做为“缓存”服务,不持久数据,数据在服务终止后将消失,此模式下也将不存在“数据恢复”的手段,是一 ...
- python2/3 发送https请求时,告警关闭方法
问题: 使用Python3 requests发送HTTPS请求,已经关闭认证(verify=False)情况下,控制台会输出以下错误: InsecureRequestWarning: Unverifi ...
- Easy ui DateBox 控件格式化显示操作
//Easy ui datebox 控件 <input class="easyui-datebox" name="StartTime" id=" ...
- 王者荣耀交流协会final发布中间产物
WBS+PSP 版本控制报告 软件功能说明书final修订
- Alpha发布_文案+美工
团队名称:探路者 1蔺依铭:http://www.cnblogs.com/linym762/ 2张恩聚:http://www.cnblogs.com/zej87/ 3米赫:http://www.cnb ...
- 欢迎来怼—第二次Scrum会议
一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华小组照片 二.开会信息 时间:2017/10/14 18:30~18:47,总计17min.地点:东北师范 ...
- 02慕课网《vue.js2.5入门》——Vue中的组件,实现todolist
TodoList功能开发 例子:输入字符,在列表中显示: 由于有v-for属性,<li>不会被渲染,它已经和数据绑定在一起,有数据来决定 input和button上都有事件监听器,inpu ...