Picture

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3075    Accepted Submission(s): 1616

Problem Description
A
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.

 
Input
Your
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.

 
Output
Your
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.
 
Sample Input
7
-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
 
Sample Output
228
 
 
 
给出 n 个矩阵 求包围这些矩阵的边界长度。
 
#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(线段树轮廓线)的更多相关文章

  1. hdu 1828 Picture(线段树 || 普通hash标记)

    http://acm.hdu.edu.cn/showproblem.php?pid=1828 Picture Time Limit: 6000/2000 MS (Java/Others)    Mem ...

  2. POJ 1177/HDU 1828 picture 线段树+离散化+扫描线 轮廓周长计算

    求n个图矩形放下来,有的重合有些重合一部分有些没重合,求最后总的不规则图型的轮廓长度. 我的做法是对x进行一遍扫描线,再对y做一遍同样的扫描线,相加即可.因为最后的轮廓必定是由不重合的线段长度组成的, ...

  3. HDU 1828 Picture (线段树+扫描线)(周长并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1828 给你n个矩形,让你求出总的周长. 类似面积并,面积并是扫描一次,周长并是扫描了两次,x轴一次,y ...

  4. HDU 1828 Picture (线段树:扫描线周长)

    依然是扫描线,只不过是求所有矩形覆盖之后形成的图形的周长. 容易发现,扫描线中的某一条横边对答案的贡献. 其实就是 加上/去掉这条边之前的答案 和 加上/去掉这条边之后的答案 之差的绝对值 然后横着竖 ...

  5. HDU 1828 Picture(长方形的周长和)

    HDU 1828 Picture 题目链接 题意:给定n个矩形,输出矩形周长并 思路:利用线段树去维护,分别从4个方向扫一次,每次多一段的时候,就查询该段未被覆盖的区间长度,然后周长就加上这个长度,4 ...

  6. hdu 4031 attack 线段树区间更新

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Subm ...

  7. hdu 4288 离线线段树+间隔求和

    Coder Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  8. hdu 3016 dp+线段树

    Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  9. HDU 1828 Picture(线段树扫描线求周长)

    Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

随机推荐

  1. Conference - open source drives IOT from device to edge

    Open source drives IOT from device to edge 以下都是针对IOT领域的项目: ACRN A Big Little Hypervisor for IoT Deve ...

  2. python基础--5字典

    #字典#dict#基本结构info={ "k1":'v1' #键值对 ,"k2":"v2"} #字典的value可以是任何值# info={ ...

  3. 基于Redis做内存管理

    1 Redis存储机制: redis存储的数据类型包括,String,Hash,List,Set,Sorted Set,它内部使用一个redisObject对象来表示所有的key和value,这个对象 ...

  4. unixbench

    1.下载 https://github.com/kdlucas/byte-unixbench/archive/v5.1.3.tar.gz 2.修改Makefile 交叉编译 #CC=gccCC = a ...

  5. 黑客教父郭盛华:提升家庭WiFi的10个方法

    中国黑客教父,知名网络安全专家郭盛华曾发博文表示:“WiFi是互联网发展过程中最重要的发展之一,虚拟世界没有百分百的安全,所以杀毒软件并不可以抵抗全部的黑客攻击.“ 用户WiFi密码尽量不要使用简单单 ...

  6. bootstrap模态框模板代码

    模态框模板 模板代码 <!-- 添加员工的模态框 start --> <div class="modal fade" id="empAddModal&q ...

  7. 一波儿networkx 读写edgelist,给节点加attribute的操作

    一波儿networkx 读写edgelist,给节点加attribute的操作 read more: nx official: Reading and writing graphs import nu ...

  8. dede标签大全

    想必很多人对后台不熟悉,并且觉得很难.其实不难,只是你们没有找到合适的方法学习而已!只有找到一个合适的学习方法,不管做什么事情,我想都很容易.学习讲究的是效率,而效率又是由思路决定的.就拿网页制作来说 ...

  9. [CSP-S模拟测试]:甜圈(线段树)

    题目描述 $D$先生,是一个了不起的甜甜圈制造商.今天,他的厨房准备在日出之前制作甜甜圈.$D$先生瞬间完成了$N$个油炸圈饼.但是,这些油炸圈饼得先经过各种装饰任务才可以成为甜甜圈销售:填充奶油,浸 ...

  10. AtCoder Regular Contest 071 D - 井井井 / ###

    题目:http://arc071.contest.atcoder.jp/tasks/arc071_b 题意: 有一个二维的平面,给你xn根竖线和ym根横线,问这些线围成的长方形(正方形)的面积和(要求 ...