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 ...
随机推荐
- R中sort(), rank(), order()
在R中,和排序相关的函数主要有三个:sort(),rank(),order(). sort(x)是对向量x进行排序,返回值排序后的数值向量.rank()是求秩的函数,它的返回值是这个向量中对应元素的“ ...
- Linux command stty
Linux command stty reference: https://blog.csdn.net/lqxandroid2012/article/details/78929506 [Purpose ...
- learning svn change commit log
将repository内hook子文件夹中的pre-revprop-change.tmpl复制改成pre-revprop-change.bat,内容改为:exit 0
- Spring框架基本代码
1.准备阶段: 2.基本引入: 接口: package com.xk.spring.kp01_hello; public interface IHello { public void nice(); ...
- nginx入门示例(二)
nginx使用域名访问 (Tip) nginx目录解析 conf/nginx.conf #主要的配置文件目录 html #nginx的默认发布目录,部署完后 网站会在这个目录 ...
- sqlalchemy(二)简单的连接示例
# -*- coding: utf-8 -*- import sqlalchemy from sqlalchemy import create_engine from sqlalchemy.ext.d ...
- SQL-33 创建一个actor表,包含如下列信息
题目描述 创建一个actor表,包含如下列信息 列表 类型 是否为NULL 含义 actor_id smallint(5) not null 主键id first_name varchar(45) ...
- pragma comment的使用 pragma预处理指令详解
pragma comment的使用 pragma预处理指令详解 #pragma comment( comment-type [,"commentstring"] ) 该宏放置一 ...
- 强震记录和GPS记录,地震波记录的区别
强震记录的是加速度数据,但gps记录的是位移数据.这样的话,强震记录应该说是近场地震数据: 那么, 为什么不干脆用近场的地震波仪器呢,是因为,地震仪记录会限幅,导致记录不全.
- GMT5.4.2 installation
具体安装步骤参考seisman github gmt5.4.2或是GMT中文社区上的说明:这里只是补充一些可能出现问题的解决方法: 需要将具神标注的可选包也都安装上. 将cmake中的configue ...