HDU 3265 扫描线(矩形面积并变形)
Posters
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5230 Accepted Submission(s): 1220
However, Ted is such a picky guy that in every poster he finds something ugly. So before he pastes a poster on the window, he cuts a rectangular hole on that poster to remove the ugly part. Ted is also a careless guy so that some of the pasted posters may overlap when he pastes them on the window.
Ted wants to know the total area of the window covered by posters. Now it is your job to figure it out.
To make your job easier, we assume that the window is a rectangle located in a rectangular coordinate system. The window’s bottom-left corner is at position (0, 0) and top-right corner is at position (50000, 50000). The edges of the window, the edges of the posters and the edges of the holes on the posters are all parallel with the coordinate axes.
The input ends with a line of single zero.
0

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 50005
#define ll root<<1
#define rr root<<1|1
#define mid (a[root].l+a[root].r)/2 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} struct node{
int l, r;
int val;
__int64 sum;
}a[N*]; struct Line{
int x1, x2, y;
int val;
Line(){}
Line(int a,int b,int c,int d){
x1=a;
x2=b;
y=c;
val=d;
}
}line[N*]; bool cmp(Line a,Line b){
return a.y<b.y;
} int xx[N*];
int n, m; int b_s(int key){
int l=, r=m;
while(l<=r){
int mm=(l+r)/;
if(xx[mm]==key) return mm;
else if(xx[mm]<key) l=mm+;
else if(xx[mm]>key) r=mm-;
}
} void build(int l,int r,int root){
a[root].l=l;
a[root].r=r;
a[root].sum=a[root].val=;
if(l==r) return;
build(l,mid,ll);
build(mid+,r,rr);
} void up(int root){
if(a[root].val) a[root].sum=xx[a[root].r+]-xx[a[root].l];
else if(a[root].l==a[root].r) a[root].sum=;
else a[root].sum=a[ll].sum+a[rr].sum;
} void update(int l,int r,int val,int root){
if(l>r) return;
if(a[root].l==l&&a[root].r==r){
a[root].val+=val;
up(root);
return;
}
if(r<=a[ll].r) update(l,r,val,ll);
else if(l>=a[rr].l) update(l,r,val,rr);
else{
update(l,mid,val,ll);
update(mid+,r,val,rr);
}
up(root);
}
main()
{
int x1, y1, x2, y2, x3, y3, x4, y4;
int i, j, k;
while(scanf("%d",&n)&&n){
k=;
m=;
for(i=;i<n;i++){
scanf("%d %d %d %d %d %d %d %d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
line[k++]=Line(x1,x3,y1,);
line[k++]=Line(x1,x3,y2,-);
line[k++]=Line(x3,x4,y1,);
line[k++]=Line(x3,x4,y3,-);
line[k++]=Line(x3,x4,y4,);
line[k++]=Line(x3,x4,y2,-);
line[k++]=Line(x4,x2,y1,);
line[k++]=Line(x4,x2,y2,-);
xx[m++]=x1;
xx[m++]=x2;
xx[m++]=x3;
xx[m++]=x4;
}
sort(xx+,xx+m);
m=unique(xx+,xx+m)-xx-;
sort(line,line+k,cmp);
build(,m,);
__int64 ans=;
for(i=;i<k-;i++){
update(b_s(line[i].x1),b_s(line[i].x2)-,line[i].val,);
ans+=a[].sum*(__int64)(line[i+].y-line[i].y);
}
printf("%I64d\n",ans);
}
}
HDU 3265 扫描线(矩形面积并变形)的更多相关文章
- [HDU 4419] Colourful Rectangle (扫描线 矩形面积并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4419 题目大意:比矩形面积并多了颜色,问染成的每种颜色的面积. 矩形面积并的扫描线维护的是长度,这道题 ...
- (HDU 1542) Atlantis 矩形面积并——扫描线
n个矩形,可以重叠,求面积并. n<=100: 暴力模拟扫描线.模拟赛大水题.(n^2) 甚至网上一种“分块”:分成n^2块,每一块看是否属于一个矩形. 甚至这个题就可以这么做. n<=1 ...
- HDU1542 扫描线(矩形面积并)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- poj 3277 City Horizon (线段树 扫描线 矩形面积并)
题目链接 题意: 给一些矩形,给出长和高,其中长是用区间的形式给出的,有些区间有重叠,最后求所有矩形的面积. 分析: 给的区间的范围很大,所以需要离散化,还需要把y坐标去重,不过我试了一下不去重 也不 ...
- HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)
版权声明:欢迎关注我的博客.本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/25471349 P ...
- [Codevs] 矩形面积求并
http://codevs.cn/problem/3044/ 线段树扫描线矩形面积求并 基本思路就是将每个矩形的长(平行于x轴的边)投影到线段树上 下边+1,上边-1: 然后根据线段树的权值和与相邻两 ...
- HDU - 1255 覆盖的面积(线段树求矩形面积交 扫描线+离散化)
链接:线段树求矩形面积并 扫描线+离散化 1.给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. 2.看完线段树求矩形面积并 的方法后,再看这题,求的是矩形面积交,类同. 求面积时,用被覆 ...
- hdu 1542 扫描线求矩形面积的并
很久没做线段树了 求矩形面积的并分析:1.矩形比较多,坐标也很大,所以横坐标需要离散化(纵坐标不需要),熟悉离散化后这个步骤不难,所以这里不详细讲解了,不明白的还请百度2.重点:扫描线法:假想有一条扫 ...
- HDU 1542.Atlantis-线段树求矩形面积并(离散化、扫描线/线段树)-贴模板
好久没写过博客了,这学期不是很有热情去写博客,写过的题也懒得写题解.现在来水一水博客,写一下若干年前的题目的题解. Atlantis Time Limit: 2000/1000 MS (Java/Ot ...
随机推荐
- excel 里面拼接 MySQL insert 语句
="('"&A2&"',"&" '"&B2&"','"&C2&& ...
- 转:UML类图几种关系的总结
转自:http://www.open-open.com/lib/view/open1328059700311.html 在UML类图中,常见的有以下几种关系: 泛化(Generalization), ...
- linux笔记:linux常用命令-用户管理命令
用户管理命令:useradd(添加用户) 用户管理命令:passwd(设置和修改用户密码) 用户管理命令:who(查看所有登录用户的信息)
- [maven] 搭建多模块企业级项目
知识点:聚合.继承.工程依赖.单元测试.多war聚合.cargo发布 ① 准备工作 参考资料 http://www.cnblogs.com/quanyongan/archive/2013/05/28/ ...
- JavaWeb基础:Servlet Response
ServletResponse简介 ServletResponse代表浏览器输出,它提供所有HttpResponse的设置接口,可以设置HttpResponse的响应状态,响应头和响应内容. 生命周期 ...
- hduoj-----(2896)病毒侵袭(ac自动机)
病毒侵袭 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- ARM汇编中的标号
标号(LABEL)是为一组机器指令所起名字,表示程序中的指令或者数据地址的符号.标号可有可无,只有当需要用符号地址来访问该语句时,才给此语句赋予标号.通过在目标地址的前面放上一个标号,可以在指令中使用 ...
- Collaborative Filtering
for i=1:6040 Ai=ratings(ratings(:,1)==i,:); for j=1:5 Labnum(i,j)=length(Ai(Ai(:,3)==j)); end num(i) ...
- IE10 CSS hack,IE兼容问题
IE10 CSS hack,IE兼容问题 作者: 雪影 发表于2013 年 4 月 25 日 分类:技术分享 | 暂无评论 | 人气: 376 度 首先,ie10不支持条件注释了. 方法一:特性检测: ...
- [转]使用Java Mission Control进行内存分配分析
jdk7u40自带了一个非常好用的工具,就是Java Mission Control.JRockit Misson Control用户应该会对mission control的很多功能十分熟悉,JRoc ...