Weird Advertisement
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=18802
Description
2DPlaneLand is a land just like a huge 2D plane. The range of X axis is 0 to 109 and the range of
Y axis is also 0 to 109
. People built houses only in integer co-ordinates and there is exactly one house
in each integer co-ordinate.
Now UseAndSmile Soap Company is launching a new soap. That's why they want to advertise
this product as much as possible. So, they selected n persons for this task. Each person will be given
a rectangular region. He will advertise the product to all the houses that lie in his region. Each
rectangular region is identied by 4 integers x1, y1, x2 and y2. That means this person will advertise
in all the houses whose x co-ordinate is between x1 and x2 (inclusive) and y co-ordinate is between y1
and y2 (inclusive).
Now after a while they realized that some houses are being advertised by more than one person.
So, they want to nd the number of houses that are advertised by at least k persons. Since you are
one of the best programmers in the city; they asked you to solve this problem.
Input
Input starts with an integer T ( 13), denoting the number of test cases.
Each case starts with a line containing two integers n (1 n 30000), k (1 k 10). Each of the
next n lines will contain 4 integers x1, y1, x2, y2 (0 x1; y1; x2; y2 109
, x1 < x2, y1 < y2) denoting a
rectangular region for a person.
Output
For each case, print the case number and the total number of houses that are advertised by at least k
people.
Renat Mullakhanov (rem. See http://www.topcoder.com/tc?module=MemberProle.cr=8394868),
one of the most talented programmers in the world, passed away on March 11, 2011. This is very
sad news for all of us. His team went to ACM ICPC World Finals - 2004, placed 4th and won gold
medals. He really was a great programmer. May he rest in peace. This problem is dedicated to him.
Sample Input
2
2 1
0 0 4 4
1 1 2 5
2 2
0 0 4 4
1 1 2 5
Sample Output
Case 1: 27
Case 2: 8
HINT
题意
给你n个矩形,然后问你整个平面上被覆盖k次及以上的面积总和是多少
题解:
扫描线,我们线段树记录一下sum[k]表示区间被覆盖k次的长度是多少
先离散化,然后按照y轴建树
然后用x轴扫过去
每次线段树区间更新就好了
代码:
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define maxn 5000000
struct line
{
int x,y1,y2,flag;
};
bool cmp(line A,line B)
{
return A.x<B.x;
}
int n,k;
typedef long long SgTreeDataType;
struct treenode
{
int L , R ;
SgTreeDataType sum[] , lazy;
void init()
{
memset(sum,,sizeof(sum));
}
};
map<int,int> H;
vector<int> Y;
treenode tree[maxn];
line p[maxn];
int tot = ;
long long ans;
inline void push_up(int o)
{
tree[o].init();
if(tree[o].L==tree[o].R)
{
int T = min(tree[o].lazy,k*1LL);
tree[o].sum[T]=Y[tree[o].R]-Y[tree[o].L-];
}
else
{
for(int i=;i<=k;i++)
{
int T = min(i+tree[o].lazy,k*1LL);
tree[o].sum[T]+=tree[o*].sum[i]+tree[o*+].sum[i];
}
}
} inline void build_tree(int L , int R , int o)
{
tree[o].L = L , tree[o].R = R, tree[o].lazy = ;
tree[o].init();
if (R > L)
{
int mid = (L+R) >> ;
build_tree(L,mid,o*);
build_tree(mid+,R,o*+);
}
push_up(o);
} inline void updata(int QL,int QR,SgTreeDataType v,int o)
{
int L = tree[o].L , R = tree[o].R;
if (QL <= L && R <= QR) tree[o].lazy+=v;
else
{
//push_down(o);
int mid = (L+R)>>;
if (QL <= mid) updata(QL,QR,v,o*);
if (QR > mid) updata(QL,QR,v,o*+);
}
push_up(o);
} int main()
{
int t;scanf("%d",&t);
for(int i=;i<=t;i++)
{
tot = ;ans=;
memset(p,,sizeof(p));
Y.clear();H.clear();
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
p[tot].x = x1,p[tot].y1=y1,p[tot].y2=y2+,p[tot].flag=;tot++;
p[tot].x = x2+,p[tot].y1=y1,p[tot].y2=y2+,p[tot].flag=-;tot++;
Y.push_back(y1);
Y.push_back(y2+);
}
sort(p,p+tot,cmp);
sort(Y.begin(),Y.end());
Y.erase(unique(Y.begin(),Y.end()),Y.end());
for(int i=;i<Y.size();i++)
H[Y[i]]=i+;
build_tree(,Y.size()+,);
for(int i=;i<tot-;i++)
{
updata(H[p[i].y1],H[p[i].y2]-,p[i].flag,);
ans+=tree[].sum[k]*(p[i+].x-p[i].x);
//cout<<p[i].y1<<" "<<p[i].y2<<" "<<p[i].flag<<endl;
//cout<<tree[1].sum[k]<<" "<<(p[i+1].x-p[i].x)<<endl;
}
printf("Case %d: %lld\n",i,ans);
}
}
uva 11983 Weird Advertisement 扫描线的更多相关文章
-
UVA 11983 Weird Advertisement(线段树求矩形并的面积)
UVA 11983 题目大意是说给你N个矩形,让你求被覆盖k次以上的点的总个数(x,y<1e9) 首先这个题有一个转化,吧每个矩形的x2,y2+1这样就转化为了求N个矩形被覆盖k次以上的区域的面 ...
-
UVA 11983 Weird Advertisement
题意:求矩形覆盖k次以上的区域总面积. 因为k≤10,可以在线段树上维护覆盖次数为0,...,k, ≥k的长度数量. 然后就是一个离散化以后扫描线的问题了. 离散化用的是半开半闭区间,以方便表示没有被 ...
-
UVA 11983 Weird Advertisement --线段树求矩形问题
题意:给出n个矩形,求矩形中被覆盖K次以上的面积的和. 解法:整体与求矩形面积并差不多,不过在更新pushup改变len的时候,要有一层循环,来更新tree[rt].len[i],其中tree[rt] ...
-
UVA11983 - Weird Advertisement(扫描线)
UVA11983 - Weird Advertisement(扫描线) 题目链接 题目大意:给你n个覆盖矩形,问哪些整数点是被覆盖了k次. 题目大意:这题和hdu1542是一个题型.可是这题求的是覆盖 ...
-
线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
-
[转载]完全版线段树 by notonlysuccess大牛
原文出处:http://www.notonlysuccess.com/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...
-
【转】线段树完全版~by NotOnlySuccess
线段树完全版 ~by NotOnlySuccess 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章了,觉 ...
-
《完全版线段树》——notonlysuccess
转载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文 ...
-
【转】 线段树完全版 ~by NotOnlySuccess
载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章 ...
随机推荐
-
Spring task executor同异步
1. spring提供了哪些任务执行器,是否有同步的任务执行器 有ThreadPoolTaskExecutor等执行器 同步可以用SyncTaskExecutor,但这个可以说不算一个线程池,因为还在 ...
-
c# 迭代器 与 集合 IEnumerable.GetEnumerator 方法
示例来源 :msdn 参考:https://msdn.microsoft.com/zh-cn/library/dscyy5s0(v=vs.110).aspx 使用匿名方法.迭代器和部分选件类创建简洁的 ...
-
navicat for mysql 显示中文乱码解决办法
最近遇到一个问题,用navicat for mysql 打开数据库时全都显示的是乱码(在用程序代码插入数据之前确保字符不是乱码),遇到问题就的寻求解决之道,百度了好长时间也没解决,网上那些解决办法 ...
-
2017年第六届数学中国数学建模国际赛(小美赛)C题解题思路
这篇文章主要是介绍下C题的解题思路,首先我们对这道C题进行一个整体的概括,结构如下: C题:经济类 第一问:发现危险人群. 发现:欺诈的方式开始.雇佣或浪漫的承诺. 数据→确定特定的经济萧条地区→确定 ...
-
Cayley图数据库的可视化(Visualize)
引入 在文章Cayley图数据库的简介及使用中,我们已经了解了Cayley图数据库的安装.数据导入以及进行查询等. Cayley图数据库是Google开发的开源图数据库,虽然功能还没有Neo4 ...
-
Serializers序列化组件
Django的序列化方法 .values 序列化结果 class BooksView(View): def get(self, request): book_list = Book.objects.v ...
-
ubuntu 12.04 64位 安装wps
1.去wps官网下载linux版的软件 http://community.wps.cn/download/ 我这里下载的是Alpha版的kingsoft-office_9.1.0.4280~a12p4 ...
-
使用webgl(three.js)创建3D机房,3D机房微模块详细介绍(升级版二)
序: 上节课已经详细描述了普通机房的实现过程,文章地址(https://www.cnblogs.com/yeyunfei/p/10473021.html) 紧接着上节课的内容 我们这节可来详细讲解机房 ...
-
Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A. Little Artem and Presents 水题
A. Little Artem and Presents 题目连接: http://www.codeforces.com/contest/669/problem/A Description Littl ...
-
Protobuf 完整解析 - 公司最常用的数据交互协议
Google Protocol Buffer(简称 Protobuf)是一种轻便高效的结构化数据存储格式,平台无关.语言无关.可扩展,可用于通讯协议和数据存储等领域. 数据交互xml.json.pro ...