UVA11983 - Weird Advertisement(扫描线)
UVA11983 - Weird Advertisement(扫描线)
题目大意:给你n个覆盖矩形,问哪些整数点是被覆盖了k次。
题目大意:这题和hdu1542是一个题型。可是这题求的是覆盖k次的点。所以pushup里面就要改一下。详细的看代码把。大概的意思就是每次都是通过以下的两个孩子节点的覆盖信息更新父节点的覆盖信息。然后这题也是须要离散化建树。比較须要注意的是这题和hdu1542不一样的地方是边界,由于那题是求面积。边界并不须要考虑。而这题是求点的个数,边界上的点也是要算的。建树的时候考虑叶子节点范围的时候就要包含边界上的点。
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define lson(x) (x<<1)
#define rson(x) ((x<<1) | 1)
const int maxn = 60005;
typedef long long ll;
struct Line {
int x, y1, y2, flag;
Line (int x, int y1, int y2, int flag) {
this->x = x;
this->y1 = y1;
this->y2 = y2;
this->flag = flag;
}
bool operator < (const Line & a) const {
return x < a.x;
}
};
struct Node {
int l, r, add;
ll s[12];
void set (int l, int r, int add) {
this->l = l;
this->r = r;
this->add = add;
}
}node[maxn * 4];
vector<int> pos;
vector<Line> L;
int n, k;
void pushup(int u) {
for (int i = 0; i <= k; i++)
node[u].s[i] = 0L;
int t;
if (node[u].l == node[u].r) {
t = min(k, node[u].add);
node[u].s[t] = pos[node[u].l + 1] - pos[node[u].l];
} else {
for (int i = 0; i <= k; i++) {
t = min (i + node[u].add, k);
node[u].s[t] += node[lson(u)].s[i] + node[rson(u)].s[i];
}
}
}
void build (int u, int l, int r) {
node[u].set(l, r, 0);
if (l == r) {
pushup(u);
return;
}
int m = (l + r)>>1;
build(lson(u), l, m);
build(rson(u), m + 1, r);
pushup(u);
}
void update (int u, int l, int r , int v) {
if (l <= node[u].l && r >= node[u].r) {
node[u].add += v;
pushup(u);
return;
}
int m = (node[u].l + node[u].r)>>1;
if (l <= m)
update (lson(u), l, r, v);
if (r > m)
update (rson(u), l, r, v);
pushup(u);
}
void init () {
int x1, y1, x2, y2;
scanf ("%d%d", &n, &k);
L.clear();
pos.clear();
for (int i = 0; i < n; i++) {
scanf ("%d%d%d%d", &x1, &y1, &x2, &y2);
L.push_back(Line(x1, y1, y2 + 1, 1));
L.push_back(Line(x2 + 1, y1, y2 + 1, -1));
pos.push_back(y1);
pos.push_back(y2 + 1);
}
sort(L.begin(), L.end());
sort(pos.begin(), pos.end());
pos.erase (unique(pos.begin(), pos.end()), pos.end());
build(1, 0, (int)pos.size() - 1);
}
ll solve () {
init();
ll ans = 0;
int l, r;
for (int i = 0; i < L.size() - 1; i++) {
l = lower_bound(pos.begin(), pos.end(), L[i].y1) - pos.begin();
r = lower_bound(pos.begin(), pos.end(), L[i].y2) - pos.begin();
update (1, l, r - 1, L[i].flag);
ans += node[1].s[k] * (L[i + 1].x - L[i].x);
}
return ans;
}
int main () {
int T;
scanf ("%d", &T);
for (int cas = 1; cas <= T; cas++)
printf ("Case %d: %lld\n", cas, solve());
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
UVA11983 - Weird Advertisement(扫描线)的更多相关文章
- uva 11983 Weird Advertisement 扫描线
Weird Advertisement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/probl ...
- UVA 11983 Weird Advertisement
题意:求矩形覆盖k次以上的区域总面积. 因为k≤10,可以在线段树上维护覆盖次数为0,...,k, ≥k的长度数量. 然后就是一个离散化以后扫描线的问题了. 离散化用的是半开半闭区间,以方便表示没有被 ...
- UVA 11983 Weird Advertisement --线段树求矩形问题
题意:给出n个矩形,求矩形中被覆盖K次以上的面积的和. 解法:整体与求矩形面积并差不多,不过在更新pushup改变len的时候,要有一层循环,来更新tree[rt].len[i],其中tree[rt] ...
- UVA 11983 Weird Advertisement(线段树求矩形并的面积)
UVA 11983 题目大意是说给你N个矩形,让你求被覆盖k次以上的点的总个数(x,y<1e9) 首先这个题有一个转化,吧每个矩形的x2,y2+1这样就转化为了求N个矩形被覆盖k次以上的区域的面 ...
- [转载]完全版线段树 by notonlysuccess大牛
原文出处:http://www.notonlysuccess.com/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...
- 【转】线段树完全版~by NotOnlySuccess
线段树完全版 ~by NotOnlySuccess 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章了,觉 ...
- 《完全版线段树》——notonlysuccess
转载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文 ...
- 【转】 线段树完全版 ~by NotOnlySuccess
载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章 ...
- 【转载】完全版线段树 by notonlysuccess大牛
原文出处:http://www.notonlysuccess.com/ 今晚上比赛就考到了 排兵布阵啊,难受. [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时 ...
随机推荐
- CentOS 6.3 安装 samba 共享(转)
PHP环境在linux下,但是开发的时候用的是windows,于是我用了samba将linux的一个目录共享,然后在windows上做映射,这样就可以直接在windows下编辑linux上的文件了 首 ...
- STM32本学习笔记EXTI(外部中断)
参考资料:STM32数据表.网络信息 =========================================切割线===================================== ...
- 【Linux探索之旅】第一部分第三课:测试并安装Ubuntu
内容简介 1.第一部分第三课:测试并安装Ubuntu 2.第一部分第四课预告:磁盘分区 测试并安装Ubuntu 大家好,经过前两个比较偏理论(是否想起了带着瓜皮帽,手拿折扇的老学究,或者腐儒)的课程, ...
- OFTP说明
OFTP (TheOdette File Transfer Protocol,RFC 2204)作为两个商业伙伴中建立EDI连接的一种协议.它由Odette-Organization于1986年创建. ...
- UVA 1358 - Generator(dp+高斯消元+KMP)
UVA 1358 - Generator option=com_onlinejudge&Itemid=8&page=show_problem&category=524& ...
- 如何成为游戏的生产者——第二章:如何开始你的编程(开发环境的搭建、C++语言适应)
如何成为游戏的生产者--文章二章:怎样開始你的编程 小故事:上节说到我六年级打开了那本C语言的书,然后其实我还是没看懂.好像看懂了一些printf语句.之后遇到了史无前例的困难--怎么让代码执行起来. ...
- UVA 239 - Tempus et mobilius. Time and motion(更换周期)
UVA 239 - Tempus et mobilius. Time and motion 题目链接 题意:这题题意也是吊得飞起,看了老半天,大概是这样: 有一个放球的队列.和3个轨道(说白了就是栈) ...
- hdoj 2183 奇数阶魔方(II) 【模拟】+【法】
比赛的时候花了一个多小时,以做不做 分析:可观察:中间是(n*n+1)/2, 中间的上面是n*n,以下是1, 左边是n,右面是(n*n+1)-n,并且正对角线是最左上对到最右下端添加(+1).另外一条 ...
- NYoj-Binary String Matching-KMP算法
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描写叙述 Given two strings A and B, whose alp ...
- struts2-dojo-plugin-2.3.1.2.jar!/struts-plugin.xml:29:119
Unable to load configuration. - bean - jar:file:/D:/code_workspace/SSHWorkSpace3/.metadata/.plugins/ ...