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 ...
随机推荐
- golang学习之beego框架配合easyui实现增删改查及图片上传
golang学习之beego框架配合easyui实现增删改查及图片上传 demo目录: upload文件夹主要放置上传的头像文件,main是主文件,所有效果如下: 主页面: 具体代码: <!DO ...
- MyBatis——优化MyBatis配置文件中的配置
原文:http://www.cnblogs.com/xdp-gacl/p/4264301.html 一.连接数据库的配置单独放在一个properties文件中 之前,我们是直接将数据库的连接配置信息写 ...
- D3.js 弦图的制作
这是一种用于描述节点之间联系的图表. 1. 弦图是什么 弦图(Chord),主要用于表示两个节点之间的联系. 两点之间的连线,表示谁和谁具有联系: 线的粗细表示权重: 2. 数据 初始数据为: var ...
- Spring MVC 之输入验证(六)
Spring MVC 验证主要还是用的是hibernate的验证.so需要添加以下的jar包: 1. hibernate-validator-5.2.2.Final.jar 2.hibernate-v ...
- phalcon: acl权限控制
目录控制: public/index.php: $di['aclResource']=function(){ return include_once '../app/config/frontbackA ...
- DialogFragment 自定义弹窗
layout文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:a ...
- iOS 控制单个控制器旋转
iOS 控制单个控制器旋转 控制单个ViewController 的旋转 //不旋转,保持竖屏 //iOS 5 - (BOOL) shouldAutorotateToInterfaceOrientat ...
- 【转】 C++的深拷贝与浅拷贝
对于普通类型的对象来说,它们之间的复制是很简单的,例如:int a=88;int b=a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员变量.下面看一个类对象拷贝的简单例子. ...
- [redis] redis 存取键值对常用的三种使用方式 - Jedis、JedisPool、Jedis分布式
|-Jedis 普通方式 |-JedisPool 连接池方式(需要引入pool相关jar) |-Jedis 分布式 (需要引入pool相关jar) 引入jedis2.7.0和commons.pool2 ...
- 集成 Apple Pay
作者感言 在中秋过后终于把国内的三大支付平台SDK集成都搞定了, 现在我们终于可以来研究Apple自家的支付Apple Pay最后:如果你有更好的建议或者对这篇文章有不满的地方, 请联系我, 我会参考 ...