UVA-11983-Weird Advertisement(线段树+扫描线)[求矩形覆盖K次以上的面积]
题意:
求矩形覆盖K次以上的面积
分析:
k很小,可以开K颗线段树,用sum[rt][i]来保存覆盖i次的区间和,K次以上全算K次
// File Name: 11983.cpp
// Author: Zlbing
// Created Time: 2013/7/21 16:06:54 #include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define CL(x,v); memset(x,v,sizeof(x));
#define INF 0x3f3f3f3f
#define LL long long
#define REP(i,r,n) for(int i=r;i<=n;i++)
#define RREP(i,n,r) for(int i=n;i>=r;i--) #define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 const int MAXN=6e4+;
struct seg{
int x1,x2,y;
int flag;
bool operator <(const seg& rsh)const{
return y<rsh.y;
}
}G[MAXN];
int hash[MAXN]; int col[MAXN<<];
int sum[MAXN<<][]; int n,m;
void build(int l,int r,int rt)
{
col[rt]=;
sum[rt][]=hash[r+]-hash[l];
for(int i=;i<=m;i++)sum[rt][i]=;
if(l==r)return;
int m=(l+r)>>;
build(lson);
build(rson);
}
void pushup(int rt,int l,int r)
{
if(col[rt]>=m)
{
memset(sum[rt],,sizeof(sum[rt]));
sum[rt][m]=hash[r+]-hash[l];
}
else if(l==r)
{
memset(sum[rt],,sizeof(sum[rt]));
sum[rt][col[rt]]=hash[r+]-hash[l];
}
else{
for(int i=;i<col[rt];i++)sum[rt][i]=;
for(int i=col[rt];i<m;i++)
{
sum[rt][i]=sum[rt<<][i-col[rt]]+sum[rt<<|][i-col[rt]];
}
sum[rt][m]=;
for(int i=m-col[rt];i<=m;i++)
{
sum[rt][m]+=sum[rt<<][i]+sum[rt<<|][i];
}
}
}
void update(int L,int R,int flag,int l,int r,int rt)
{
if(L<=l&&R>=r)
{
col[rt]+=flag;
pushup(rt,l,r);
return;
}
int m=(l+r)>>;
if(L<=m)update(L,R,flag,lson);
if(R>m)update(L,R,flag,rson);
pushup(rt,l,r);
}
int main()
{
int T;
scanf("%d",&T);
int cas=;
while(T--)
{
scanf("%d%d",&n,&m);
int a,b,c,d;
int xlen=;
for(int i=;i<n;i++)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
c++,d++;
G[xlen]=(seg){a,c,b,};
//G[xlen].x1=a,G[xlen].x2=c,G[xlen].y=b,G[xlen].flag=1;
hash[xlen]=a;
xlen++;
G[xlen]=(seg){a,c,d,-};
//G[xlen].x1=a,G[xlen].x2=c,G[xlen].y=d,G[xlen].flag=-1;
hash[xlen]=c;
xlen++;
}
sort(G,G+xlen);
sort(hash,hash+xlen);
int len=unique(hash,hash+xlen)-hash;
LL ans=;
build(,xlen-,);
for(int i=;i<xlen-;i++)
{
int x1=lower_bound(hash,hash+len,G[i].x1)-hash;
int x2=lower_bound(hash,hash+len,G[i].x2)-hash-;
update(x1,x2,G[i].flag,,xlen-,);
//printf("sum[1][m]=%I64d h=%d\n",sum[1][m],G[i+1].y-G[i].y);
ans+=(LL)sum[][m]*(LL)(G[i+].y-G[i].y);
}
printf("Case %d: %lld\n",cas++,ans);
}
return ;
}
UVA-11983-Weird Advertisement(线段树+扫描线)[求矩形覆盖K次以上的面积]的更多相关文章
- UVA 11983 Weird Advertisement --线段树求矩形问题
题意:给出n个矩形,求矩形中被覆盖K次以上的面积的和. 解法:整体与求矩形面积并差不多,不过在更新pushup改变len的时候,要有一层循环,来更新tree[rt].len[i],其中tree[rt] ...
- HDU 1828“Picture”(线段树+扫描线求矩形周长并)
传送门 •参考资料 [1]:算法总结:[线段树+扫描线]&矩形覆盖求面积/周长问题(HDU 1542/HDU 1828) •题意 给你 n 个矩形,求矩形并的周长: •题解1(两次扫描线) 周 ...
- hdu1542 线段树扫描线求矩形面积的并
题意: 给你n个正方形,求出他们的所占面积有多大,重叠的部分只能算一次. 思路: 自己的第一道线段树扫描线题目,至于扫描线,最近会写一个总结,现在就不直接在这里写了,说下我的方 ...
- hdu1828 线段树扫描线求矩形面积的周长
题意: 给你n个矩形,问你这n个矩形所围成的图形的周长是多少. 思路: 线段树的扫描线简单应用,这个题目我用的方法比较笨,就是扫描两次,上下扫描,求出多边形的上下边长和,然后同 ...
- 2015 UESTC 数据结构专题E题 秋实大哥与家 线段树扫描线求矩形面积交
E - 秋实大哥与家 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...
- HDU 1542"Atlantis"(线段树+扫描线求矩形面积并)
传送门 •题意 给你 n 矩形,每个矩形给出你 $(x_1,y_1),(x_2,y_2)$ 分别表示这个矩形的左下角和右上角坐标: 让你求这 n 个矩形并的面积: 其中 $x \leq 10^{5} ...
- poj 1177 --- Picture(线段树+扫描线 求矩形并的周长)
题目链接 Description A number of rectangular posters, photographs and other pictures of the same shape a ...
- hdu 1542&&poj 1151 Atlantis[线段树+扫描线求矩形面积的并]
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- hdu 1542(线段树+扫描线 求矩形相交面积)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
随机推荐
- Java基础知识强化07:打印出空心菱形
1.如图打印出空心菱形: 2.下面是逻辑实现代码: package himi.hebao04; import java.util.Scanner; public class TestDemo08 { ...
- list-style无颜色问题解决,list-style-type无颜色解决
list-style无颜色问题解决,list-style-type无颜色解决 >>>>>>>>>>>>>>>& ...
- springmvc配置文件 spring-servlet
<?xml version="1.0" encoding="UTF-8"?><!-- Bean头部 --><beans xmlns ...
- python之enumerate枚举 第二篇(六):enumerate枚举
[Python之旅]第二篇(六):enumerate枚举 python enumerate枚举 摘要: 1.普通情况下打印列表中索引号及其对应元素 使用下面的循环: 1 2 3 4 5 6 ...
- shell跑一个PHP脚本的简单命令
最近在做一个刷数据库的小功能,需要批量添加到不同的表中,写好PHP文件之后,登录到某一个服务器上面 上传文件的命令:rz 会出现一个弹框可以选择要上传的文件 执行文件并报错误的命令:/usr/loca ...
- angularjs 将带标签的内容解析后返回
参考地址:http://okashii.lofter.com/post/1cba87e8_29e0fab 引入angular-sanitize.js文件 注入ngSanitize 页面数据绑定 ng- ...
- webServices 执行流程,(我是菜鸟,我怕谁,仅代表个人理解,欢迎各位大神们指导,不和您的胃口,请默默离开!!)
二.上图仅仅代表个人理解,下面以代码方式解释一下. (1) strtus.xml <?xml version="1.0" encoding="UTF-8" ...
- oc常用正则表达式
常用的第三方正则库: http://regexkit.sourceforge.net/RegexKitLite/index.html 匹配中文字符的正则表达式: [\u4e00-\u9fa5]评注:匹 ...
- animationWithKeyPath键值对
animationWithKeyPath键值对的方式来改变动画 <Jacky Shin:可以从这个网址查到哪些可以做为动画效果, 打开xcode帮助,搜索animatable propertie ...
- java常用指令
javac 编译java源文件到字节码文件 -d XXX 1.指定编译后的字节码文件存放位置. 2.若编译的java源文件中使用包名,则根据包名生成相应的子目录 javac -d . Hello.ja ...