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/ 今晚上比赛就考到了 排兵布阵啊,难受. [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时 ...
随机推荐
- 输出无名空数组---精android、IOS App应用服务程序开发
直接输出 [] 示例文件_samples/app/array_null.json在轻开平台的_samples/app/文件夹下 太Easy.无法写出很多其它的内容,大家还是自己试试吧! ! ! 相关资 ...
- android imageButton 透明图片
在Android有许多不规则button.例如: 这个时候,我们假设想做成不规则button的话.第一步就是搞一张边缘透明的png图片,然后用src指定到他.这个时候我们会发现,还没有达到要的效果.还 ...
- linux根据该文件夹的读取权限和权限运行差异
假设你linux下使用ls.细心的你会发现居然夹有权限运行.例如: drwxrwxr-x 11 cl cl 4096 9 25 14:22 ./ drwxr-xr-x 49 cl cl 4096 1 ...
- cocos2d-x路~使得第一个字游戏(一个)
前言 去年的回忆.另外,在第三.他们开发了他们的第一场比赛四月,它是游戏.所以我决定走上独立开发的道路上.了.第一款游戏达到它应有的盈利水平.然而这款游戏开发后的时间里.都没再取得还有一款令自己惬意的 ...
- YT新人之巅峰大决战04
Problem Description Eddy's interest is very extensive, recently he is interested in prime number. Ed ...
- java提高篇(四)-----抽象类与接口
接口和内部类为我们提供了一种将接口与实现分离的更加结构化的方法. 抽象类与接口是java语言中对抽象概念进行定义的两种机制,正是由于他们的存在才赋予java强大的面向对象的能力.他们两者之间对抽象概念 ...
- Codeforces Round #270(利用prim算法)
D. Design Tutorial: Inverse the Problem time limit per test 2 seconds memory limit per test 256 mega ...
- Visual Studio 使用及调试必知必会
原文:Visual Studio 使用及调试必知必会 一:C# CODING 技巧 1:TODO 然后 CTRL + W + T,打开任务列表,选中 Comments,就会显示所有待做的任务 2: ...
- 【Andrioid】在Gradle编译时生成一个不同的版本号,动态设置应用程序标题,应用程序图标,更换常数
写项目的时候常常会遇到下面的情况: 1.须要生成測试版本号和正式版本号的apk 2.測试版本号和正式版本号的URL是不一样的 3.測试版本号和正式版本号的包名须要不一致,这样才干安装到同一部手机上面. ...
- Unity 3D使用GameObject创建一个简单的可移动物体
于Unity 3D游戏的开发.游戏脚本需要3D模拟组合,该脚本将被写入阻力3D为了达到效果对象. 以下是一个小实例,使用Unity 3D实现一个可控制移动的小人.小人能够向前.向后.向左和向右移动. ...