hdu 1828 Picture(线段树轮廓线)
Picture
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3075 Accepted Submission(s): 1616
number of rectangular posters, photographs and other pictures of the
same shape are pasted on a wall. Their sides are all vertical or
horizontal. Each rectangle can be partially or totally covered by the
others. The length of the boundary of the union of all rectangles is
called the perimeter.
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.
program is to read from standard input. The first line contains the
number of rectangles pasted on the wall. In each of the subsequent
lines, one can find the integer coordinates of the lower left vertex and
the upper right vertex of each rectangle. The values of those
coordinates are given as ordered pairs consisting of an x-coordinate
followed by a y-coordinate.
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.
program is to write to standard output. The output must contain a
single line with a non-negative integer which corresponds to the
perimeter for the input rectangles.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
using namespace std;
typedef pair<int,int> pii ;
typedef long long LL;
#define X first
#define Y second
#define root 1,n,1
#define lr rt<<1
#define rr rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = ;
const int mod = ;
int n , m ;
struct Point { int x , y ;Point(){} };
struct Line{ int tag ; Point a, b ; }e[N];
inline bool cmp1 ( const Line &A , const Line &B ) { return A.a.x < B.a.x ; }
inline bool cmp2 ( const Line &A , const Line &B ) { return A.a.y < B.a.y ; } int lazy[N<<] , cnt[N<<] , sum[N<<] ; void build( int l , int r , int rt ) {
sum[rt] = lazy[rt] = cnt[rt] = ;
if( l == r ) return ;
int mid = (l+r)>>;
build(lson),build(rson);
} void Up( int l , int r , int rt ) {
if( cnt[rt] > ) sum[rt] = r - l + ;
else sum[rt] = sum[lr] + sum[rr] ;
} void update( int l , int r , int rt , int L , int R , int tag ) {
if( l == L && r == R ) {
if( tag ) {
cnt[rt]++ , lazy[rt] ++ ;
sum[rt] = r - l + ;
}
else {
cnt[rt]-- , lazy[rt] -- ;
if( cnt[rt] > ) sum[rt] = r - l + ;
else {
if( l == r ) sum[rt] = ;
else sum[rt] = sum[lr] + sum[rr] ;
}
}
return ;
}
int mid = (l+r)>>;
if( L > mid ) update(rson,L,R,tag);
else if( R <= mid ) update(lson,L,R,tag);
else update(lson,L,mid,tag) , update(rson,mid+,R,tag);
Up(l,r,rt);
} int x1[N] , x2[N] , y1[N] , y2[N]; int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif // LOCAL
int _ , cas = ;
int mx , Mx , my , My ;
while( scanf("%d",&n) != EOF ) {
Mx = My = -N , mx = my = N ;
for( int i = ; i < n ; ++i ) {
scanf("%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i]);
mx = min( mx , x1[i] ); Mx = max( Mx , x2[i] );
my = min( my , y1[i] ); My = max( My , y2[i] );
e[i].a.x = x1[i] , e[i].a.y = y1[i] ;
e[i].b.x = x1[i] , e[i].b.y = y2[i] ;
e[i].tag = ;
e[i+n].a.x = x2[i] , e[i+n].a.y = y2[i];
e[i+n].b.x = x2[i] , e[i+n].b.y = y1[i];
e[i+n].tag = ;
}
int tot = n * ;
sort( e , e + tot ,cmp1 ) ;
LL ans = , last = ;
build( my , My - , );
for( int i = ; i < tot ; ++i ) {
int x = e[i].a.y , y = e[i].b.y ;
if( x > y ) swap(x,y);
update( my , My - , , x , y - , e[i].tag );
LL tmp = sum[] ;
ans += abs( tmp - last );
last = tmp ;
}
for( int i = ; i < n ; ++i ){
e[i].a.x = x1[i] , e[i].a.y = y1[i] ;
e[i].b.x = x2[i] , e[i].b.y = y1[i] ;
e[i].tag = ;
e[i+n].a.x = x2[i] , e[i+n].a.y = y2[i] ;
e[i+n].b.x = x1[i] , e[i+n].b.y = y2[i] ;
e[i+n].tag = ;
}
last = ;
sort( e , e + tot , cmp2 ) ;
build(mx,Mx-,);
for( int i = ; i < tot ; ++i ) {
int x = e[i].a.x , y = e[i].b.x ;
if( x > y ) swap(x,y);
update( mx , Mx - , , x , y - , e[i].tag );
LL tmp = sum[] ;
ans += abs( tmp - last );
last = tmp ;
}
printf("%I64d\n",ans);
}
}
hdu 1828 Picture(线段树轮廓线)的更多相关文章
- hdu 1828 Picture(线段树 || 普通hash标记)
http://acm.hdu.edu.cn/showproblem.php?pid=1828 Picture Time Limit: 6000/2000 MS (Java/Others) Mem ...
- POJ 1177/HDU 1828 picture 线段树+离散化+扫描线 轮廓周长计算
求n个图矩形放下来,有的重合有些重合一部分有些没重合,求最后总的不规则图型的轮廓长度. 我的做法是对x进行一遍扫描线,再对y做一遍同样的扫描线,相加即可.因为最后的轮廓必定是由不重合的线段长度组成的, ...
- HDU 1828 Picture (线段树+扫描线)(周长并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1828 给你n个矩形,让你求出总的周长. 类似面积并,面积并是扫描一次,周长并是扫描了两次,x轴一次,y ...
- HDU 1828 Picture (线段树:扫描线周长)
依然是扫描线,只不过是求所有矩形覆盖之后形成的图形的周长. 容易发现,扫描线中的某一条横边对答案的贡献. 其实就是 加上/去掉这条边之前的答案 和 加上/去掉这条边之后的答案 之差的绝对值 然后横着竖 ...
- HDU 1828 Picture(长方形的周长和)
HDU 1828 Picture 题目链接 题意:给定n个矩形,输出矩形周长并 思路:利用线段树去维护,分别从4个方向扫一次,每次多一段的时候,就查询该段未被覆盖的区间长度,然后周长就加上这个长度,4 ...
- hdu 4031 attack 线段树区间更新
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Subm ...
- hdu 4288 离线线段树+间隔求和
Coder Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- hdu 3016 dp+线段树
Man Down Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- HDU 1828 Picture(线段树扫描线求周长)
Picture Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
随机推荐
- Matlab 多个版本的安装包下载、安装和激活教程 + 多套数学建模视频教程
目录 1. 关键词 1.1. 说明 2. 下载地址 2.1. OneDrive高速云盘 2.1.1. 多版本的安装包 2.1.2. 多套数学建模的视频教程 2.2. 百度云 3. 安装教程 1. 关键 ...
- IC设计流程介绍
芯片设计分为前端设计和后端设计,前端设计(也称逻辑设计)和后端设计(也称物理设计)并没有统一严格的界限,涉及到与工艺有关的设计就是后端设计. 1. 规格制定 芯片规格,也就像功能列表一样 ...
- 体验一把haskell
这几天做到PAT一道比较数据大小的题PAT1065,题目不难,应该说是一道送分题,就是开数组,然后模拟人工计算的过程进行计算,再比较下就行.做完之后,联想到haskell的Integer类型是无限大的 ...
- 带你一文搞定 IO 流相关核心问题
问:简单谈谈 Java IO 流各实现类的特性? 答:java.io 包下面的流基本都是装饰器模式的实现,提供了各种类型流操作的便携性,常见的流分类如下. 以二进制字节方式读写的流: InputStr ...
- Test 6.29 T2 染色
问题描述 于是 CJK 轻轻松松就切了第一题."好,那么来看看第二题吧." JesseLiu 大手一挥,CJK 眼前立刻出现了一棵有 n 个节点的树."现在,你将要为这颗 ...
- LeetCode--055--跳跃游戏(java)
给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: true ...
- 如何利用阿里视频云开源组件,快速自定义你的H5播放器?
摘要: Aliplayer希望提供一种方便.简单.灵活的机制,让客户能够扩展播放器的功能,并且Aliplayer提供一些组件的基本实现,用户可以基于这些开源的组件实现个性化功能,比如自定义UI和自己A ...
- HDU6669 Game(思维,贪心)
HDU6669 Game 维护区间 \([l,r]\) 为完成前 \(i\) 步使用最少步数后可能落在的区间. 初始时区间 \([l,r]\) 为整个坐标轴. 对于第 \(i\) 个任务区间 \([a ...
- Tomcat GC参数详解
tomcat启动参数,将JVM GC信息写入tomcat_gc.log CATALINA_OPTS='-Xms512m -Xmx4096m -XX:PermSize=64M -XX:MaxNewSiz ...
- ERROR 1292 (22007): Truncated incorrect DOUBLE value: 'asfsda1'
mysql> UPDATE financial_sales_order SET ASSIGN_TIME = '2018-05-02 00:00:00' where CUSTOMER_ID=354 ...