HDU3265 线段树(扫描线)
Posters |
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 14 Accepted Submission(s): 6 |
Problem Description
Ted has a new house with a huge window. In this big summer, Ted decides to decorate the window with some posters to prevent the glare outside. All things that Ted can find are rectangle posters.
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. |
Input
The input contains several test cases. For each test case, the first line contains a single integer N (0<N<=50000), representing the total number of posters. Each of the following N lines contains 8 integers x1, y1, x2, y2, x3, y3, x4, y4, showing details about one poster. (x1, y1) is the coordinates of the poster’s bottom-left corner, and (x2, y2) is the coordinates of the poster’s top-right corner. (x3, y3) is the coordinates of the hole’s bottom-left corner, while (x4, y4) is the coordinates of the hole’s top-right corner. It is guaranteed that 0<=xi, yi<=50000(i=1…4) and x1<=x3<x4<=x2, y1<=y3<y4<=y2.
The input ends with a line of single zero. |
Output
For each test case, output a single line with the total area of window covered by posters.
|
Sample Input
|
Sample Output
|
Source
2009 Asia Ningbo Regional Contest Hosted by NIT
|
题意:
用n个”回“字形的纸贴窗子,问覆盖面积。
代码:
- //把回字拆成4段再计算就行了,要用longlong
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- const int maxn=;
- int cnt[maxn*],sum[maxn*];
- struct node{
- int l,r,h,d;
- node(){}
- node(int a,int b,int c,int d):l(a),r(b),h(c),d(d){}
- bool operator < (const node&p)const{
- if(h==p.h) return d>p.d;
- return h<p.h;
- }
- }nodes[maxn*];
- void pushup(int l,int r,int rt){
- if(cnt[rt]) sum[rt]=r-l+;
- else if(l==r) sum[rt]=;
- else sum[rt]=sum[rt<<]+sum[rt<<|];
- }
- void build(int l,int r,int rt){
- cnt[rt]=sum[rt]=;
- if(l==r) return;
- int m=(l+r)>>;
- build(l,m,rt<<);
- build(m+,r,rt<<|);
- }
- void update(int L,int R,int c,int l,int r,int rt){
- if(L<=l&&R>=r){
- cnt[rt]+=c;
- pushup(l,r,rt);
- return;
- }
- int m=(l+r)>>;
- if(L<=m) update(L,R,c,l,m,rt<<);
- if(R>m) update(L,R,c,m+,r,rt<<|);
- pushup(l,r,rt);
- }
- int main()
- {
- int t,x1,x2,x3,x4,y1,y2,y3,y4;
- while(scanf("%d",&t)&&t){
- int m=,lbd=,rbd=;
- while(t--){
- scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
- nodes[m++]=node(x1,x2,y1,);
- nodes[m++]=node(x1,x2,y3,-);
- nodes[m++]=node(x1,x2,y4,);
- nodes[m++]=node(x1,x2,y2,-);
- nodes[m++]=node(x1,x3,y3,);
- nodes[m++]=node(x1,x3,y4,-);
- nodes[m++]=node(x4,x2,y3,);
- nodes[m++]=node(x4,x2,y4,-);
- lbd=min(lbd,x1);
- rbd=max(rbd,x2);
- }
- build(lbd,rbd-,);
- sort(nodes,nodes+m);
- long long ans=;
- for(int i=;i<m-;i++){
- if(nodes[i].l<=nodes[i].r-)
- update(nodes[i].l,nodes[i].r-,nodes[i].d,lbd,rbd-,);
- ans+=(long long)sum[]*(nodes[i+].h-nodes[i].h);//注意 long long
- }
- printf("%I64d\n",ans);
- }
- return ;
- }
HDU3265 线段树(扫描线)的更多相关文章
- 【Codeforces720D】Slalom 线段树 + 扫描线 (优化DP)
D. Slalom time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)
题目链接:http://codeforces.com/contest/522/problem/D 题目大意: 给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...
- 【POJ-2482】Stars in your window 线段树 + 扫描线
Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11706 Accepted: ...
- HDU 4419 Colourful Rectangle --离散化+线段树扫描线
题意: 有三种颜色的矩形n个,不同颜色的矩形重叠会生成不同的颜色,总共有R,G,B,RG,RB,GB,RGB 7种颜色,问7种颜色每种颜色的面积. 解法: 很容易想到线段树扫描线求矩形面积并,但是如何 ...
- BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤
3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...
- BZOJ-3225 立方体覆盖 线段树+扫描线+乱搞
看数据范围像是个暴力,而且理论复杂度似乎可行,然后被卡了两个点...然后来了个乱搞的线段树+扫描线.. 3225: [Sdoi2008]立方体覆盖 Time Limit: 2 Sec Memory L ...
- hdu 5091(线段树+扫描线)
上海邀请赛的一道题目,看比赛时很多队伍水过去了,当时还想了好久却没有发现这题有什么水题的性质,原来是道成题. 最近学习了下线段树扫描线才发现确实是挺水的一道题. hdu5091 #include &l ...
- POJ1151+线段树+扫描线
/* 线段树+扫描线+离散化 求多个矩形的面积 */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...
- POJ-1151-Atlantis(线段树+扫描线+离散化)[矩形面积并]
题意:求矩形面积并 分析:使用线段树+扫描线...因为坐标是浮点数的,因此还需要离散化! 把矩形分成两条边,上边和下边,对横轴建树,然后从下到上扫描上去,用col表示该区间有多少个下边,sum代表该区 ...
- HDU 5107 线段树扫描线
给出N个点(x,y).每一个点有一个高度h 给出M次询问.问在(x,y)范围内第k小的高度是多少,没有输出-1 (k<=10) 线段树扫描线 首先离散化Y坐标,以Y坐标建立线段树 对全部的点和询 ...
随机推荐
- 单元测试模块unittest使用学习
工作原理: unittest中最核心的四个概念是:test case, test suite, test runner, test fixture. 一个TestCase的实例就是一个测试用例.什么是 ...
- Python3 Tkinter-Spinbox
1.创建 from tkinter import * root=Tk() Spinbox(root).pack() root.mainloop() 2.参数 from_ 最小值 to 最大 ...
- java DTO 转 POJO
如果这两个类的要转化的属性其属性名不一样的话,那只能用get和set方法赋值 如果你的两个类要转化的属性名都一样,那可以用org.springframework.beans.BeanUtils这个类来 ...
- 1.linux环境配置
首先说一下,这里是虚拟机环境. 1.用vbox安装centos6.8-mini 注意不要使用复制的方式安装,复制的虚拟机网络不通 安装如下: 主机 ip 角色 内存 hadoop1 192.168.0 ...
- 转:Linux 编译安装 Mysql5.7
http://broqiang.com/2017/04/18/Mysql-Install-5.7.18-Linux-Compile/ 原文 Linux 编译安装 Mysql5.7 Ubuntu 下快速 ...
- C语言实验——时间间隔
Description 从键盘输入两个时间点(24小时制),输出两个时间点之间的时间间隔,时间间隔用“小时:分钟:秒”表示. 如:3点5分25秒应表示为--03:05:25.假设两个时间在同一天内,时 ...
- 异常概念和处理机制,try-catch-finally,throw和throws,自定义异常
异常概念和处理机制 什么是异常? 所谓异常就是指在程序运行的过程中发生的一些不正常事件.(如除0溢出,数组下标越界,所要读取的文件不存在); 异常导致的后果? Java程序的执行过程中如出现异常事件, ...
- python异步初步窥探
1.异步之难:因为其执行吮吸不可预料,当下正要发生什么事件不可预料. 程序下一步行为往往依赖上一步值执行结果,如何知晓上次异步调用已完成并获取结果, 回调成了必然选择,那又 ...
- freefcw/hustoj Install Guide
First of all, this version hustoj is a skin and improved for https://code.google.com/p/hustoj/. So t ...
- Java常用类之StringBuffer
StringBuffer 类: 1. java.lang.StringBuffer 代表可变的字符序列: 2. StringBuffer 和 String 类似,但是 StringBuffer 可以对 ...