hdu2461 Rectangles 线段树--扫描线
You are developing a software for painting rectangles on the screen. The software supports drawing several rectangles and filling some of them with a color different from the color of the background. You are to implement an important function. The function answer such queries as what is the colored area if a subset of rectangles on the screen are filled.
扫描线裸题
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn=; int st[maxn<<],cov[maxn<<],y[maxn];
int Q[maxn]; struct rect{
int x1,y1,x2,y2;
}R[maxn]; struct seg{
int x,y1,y2,c;
bool operator < (const seg a)const{
return x<a.x;
}
}s[maxn]; inline void build(){
memset(st,,sizeof(st));
memset(cov,,sizeof(cov));
} void pushup(int o,int l,int r){
if(cov[o])st[o]=y[r]-y[l];
else if(l+==r)st[o]=;
else st[o]=st[o<<]+st[o<<|];
} void update(int o,int l,int r,seg a){
if(a.y1<=y[l]&&a.y2>=y[r]){
cov[o]+=a.c;
pushup(o,l,r);
return;
}
if(l+==r)return;
int m=l+((r-l)>>);
if(a.y1<y[m])update(o<<,l,m,a);
if(a.y2>y[m])update(o<<|,m,r,a);
pushup(o,l,r);
} int main(){
int n,m,c=;
while(scanf("%d%d",&n,&m)!=EOF&&n+m){
printf("Case %d:\n",++c);
for(int i=;i<=n;++i)scanf("%d%d%d%d",&R[i].x1,&R[i].y1,&R[i].x2,&R[i].y2);
build();
for(int q=;q<=m;++q){
int k;
scanf("%d",&k);
int cnt=;
for(int i=;i<=k;++i){
int num;
scanf("%d",&num);
++cnt;
s[cnt].x=R[num].x1;s[cnt].y1=R[num].y1;s[cnt].y2=R[num].y2;
s[cnt].c=;
y[cnt]=R[num].y1;
++cnt;
s[cnt].x=R[num].x2;s[cnt].y1=R[num].y1;s[cnt].y2=R[num].y2;
s[cnt].c=-;
y[cnt]=R[num].y2;
}
sort(y+,y+cnt+);
int t=unique(y+,y+cnt+)-(y+);
sort(s+,s+cnt+);
int sum=;
for(int j=;j<cnt;++j){
update(,,t,s[j]);
sum+=st[]*(s[j+].x-s[j].x);
}
update(,,t,s[cnt]);
printf("Query %d: %d\n",q,sum);
}
printf("\n");
}
return ;
}
hdu2461 Rectangles 线段树--扫描线的更多相关文章
- hdu 1828 线段树扫描线(周长)
Picture Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu1542 Atlantis (线段树+扫描线+离散化)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 1542 - Atlantis - [线段树+扫描线]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)
版权声明:欢迎关注我的博客.本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/25471349 P ...
- 【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 ...
随机推荐
- java 一些容易忽视的小点-数据类型和运算符篇
注释 文档注释: 以"/**"开头以"*/"结尾,注释中包含一些说明性的文字及一些JavaDoc标签(后期写项目时,可以生成项目的API) 行注释: 以 ...
- Uva LA 3177 - Beijing Guards 贪心,特例分析,判断器+二分,记录区间内状态数目来染色 难度: 3
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 【转】C语言中字符串输入的三种方法
在网上看到,讲的还算详细,转过来学习一下...... ======================================================================= 使 ...
- 关于iOS设备的那些事
首先推荐一个在用的库XYQuick 地址:https://github.com/uxyheaven/XYQuick idfa: 获取方式 [ASIdentifierManager sharedMana ...
- C语言进度条实现。(转)
#include <stdio.h> #include <windows.h> //跟新进度条函数 /* * 每传入一个参数就刷新一次进度条 * 当i*<=percent ...
- MyEclipse复制js文件乱码
MyEclipse复制js文件乱码 右击js文件:
- 特殊权限set_uid
set_uid:该权限针对二进制可执行文件,使文件执行阶段具有文件所有者的权限.比如passwd这个命令就具有该权限.当普通用户执行passwd命令时,可以临时获得root权限,从而可以更改密码. 作 ...
- 201621123001 《Java程序设计》第11周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 一个进程可以同时运行多个不同线程,不同的线程执行不同的任务 Java线程是通过java.lang包中定义的Thre ...
- Capjoint
前期知识储备: 现如今的全球台站分布情况:在全球大陆的分布并不均衡.在美国加利福尼亚.日本.中国台湾等地区,台站分布密集,数字化程度高.然而在世界很多地区发生的地震,往往在300km范围内仅有2到3个 ...
- 如何正确认识Docker Kubernetes 和 Apache Mesos
参考链接: http://geek.csdn.net/news/detail/229382