博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU1828 Picture 线段树+扫描线模板题
阅读量:4676 次
发布时间:2019-06-09

本文共 3190 字,大约阅读时间需要 10 分钟。

Picture

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 6332    Accepted Submission(s): 2951

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

 

代码如下

#include #include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define fuck(x) cout<<"["<
<<"]";#define FIN freopen("input.txt","r",stdin);#define FOUT freopen("output.txt","w+",stdout);#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;typedef long long LL;typedef pair
PII;const int maxn = 1e5+5;struct node1{ int l,r; int cover; int len; int lbt,rbt; int segnum;}st[maxn<<2];struct node2{ int x,y1,y2; int flag;}edge[maxn];int Y[maxn];void build(int root,int l,int r){ st[root].l=l; st[root].r=r; st[root].cover=st[root].len=0; st[root].lbt=st[root].rbt=0; st[root].segnum=0; if(r-l==1) return; int mid=(l+r+1)/2; build(root<<1,l,mid); build(root<<1|1,mid,r);}void update(int root){ if(st[root].cover>0){ st[root].len=Y[st[root].r]-Y[st[root].l]; st[root].lbt=st[root].rbt=1; st[root].segnum=1; }else if(st[root].r-st[root].l==1){ st[root].len=0; st[root].lbt=st[root].rbt=0; st[root].segnum=0; }else{ st[root].len=st[root<<1].len+st[root<<1|1].len; st[root].lbt=st[root<<1].lbt; st[root].rbt=st[root<<1|1].rbt; st[root].segnum=st[root<<1].segnum+st[root<<1|1].segnum-st[root<<1].rbt*st[root<<1|1].lbt; }}void update(int root,int val,int y1,int y2){ if(y1<=Y[st[root].l]&&Y[st[root].r]<=y2){ st[root].cover+=val; }else{ int mid=(st[root].l+st[root].r+1)/2; if(y1
Y[mid]) update(root<<1|1,val,y1,y2); } update(root);}bool cmp(node2 a,node2 b){ if(a.x==b.x) return a.y1
View Code

 

转载于:https://www.cnblogs.com/buerdepepeqi/p/9374499.html

你可能感兴趣的文章
ASP.NET AjaxPro的应用 .AjaxPro使用中“XXX未定义”的一种解决方法(转载的)
查看>>
谷歌和HTTPS
查看>>
Linux 系统的IP与域名解析文件[局域网的DNS]
查看>>
各种实用类
查看>>
【LGP5161】WD与数列
查看>>
最近素数问题——C语言
查看>>
Oracle和Mysql的区别 转载
查看>>
GOF23设计模式
查看>>
Python自然语言处理学习笔记(41):5.2 标注语料库
查看>>
新手安装Ubuntu操作系统
查看>>
山寨“饿了么”应用中添加菜品数量按钮效果
查看>>
【Fate/kaleid liner 魔法少女☆伊莉雅】系列中实践的、新世代的动画摄影工作流...
查看>>
TCP/IP系列——长连接与短连接的区别
查看>>
Linux基础——常用命令
查看>>
Python学习笔记三(文件操作、函数)
查看>>
二进制分组
查看>>
[ACM] POJ 1068 Parencodings(模拟)
查看>>
Drools只执行一个规则或者执行完当前规则之后不再执行其他规则(转)
查看>>
20180110小测
查看>>
冰点还原8.57 官方中文版下载
查看>>