poj 2528 Mayor's posters(线段树)
题目:http://poj.org/problem?id=2528
题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度。现在往墙上贴N张海报,每张海报的宽度是任意的,
但是必定是单位宽度的整数倍,且<=1QW。后贴的海报若与先贴的海报有交集,后贴的海报必定会全部或局部覆盖
先贴的海报。现在给出每张海报所贴的位置(左端位置和右端位置),问张贴完N张海报后,还能看见多少张海报?
(离散化)+ 线段树
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = +;
int n, cnt;
int map[*maxn][], ans, f[*maxn];
struct node
{
int l, r, n; //n代表是哪种颜色
} a[*maxn];
struct node2
{
int point, num; //原来点的编号, 新编的号
} s[*maxn];
void init(int l, int r, int i) //建树
{
a[i].l = l;
a[i].r = r;
a[i].n = ;
if(l != r)
{
int mid = (l+r)/;
init(l, mid, *i);
init(mid+, r, *i+);
}
}
void insert(int i, int l, int r, int m)//从第i个点,查找区间【l,r】,并把颜色标记为m
{
if(a[i].l == l && a[i].r == r)
{
a[i].n = m;
return;
}
int mid = (a[i].l+a[i].r)/;
if(a[i].n>) //颜色已有,对其子树赋值
{
a[*i].n = a[i].n;
a[*i+].n = a[i].n;
a[i].n = ;
}
if(l >= a[*i+].l)
insert(*i+, l, r, m);
else if(r <= a[*i].r)
insert(*i, l, r, m);
else
{
insert(*i, l, mid, m);
insert(*i+, mid+, r, m);
}
}
void solve(int i)
{
if(a[i].n)
{
if(!f[a[i].n])
{
ans++;
f[a[i].n] = ;
}
return;
}
solve(*i);
solve(*i+);
}
int cmp(node2 x, node2 y)
{
return x.point<y.point;
} int main()
{
int t, i, tmp, cnt;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(i = ; i < n; i++)
{
scanf("%d%d", &map[i][], &map[i][]);
s[i*].point = map[i][];
s[i*+].point = map[i][];
s[*i].num = -(i+);
s[*i+].num = i+;
}
sort(s, s+*n, cmp);
tmp = s[].point;
cnt = ;
for(i = ; i < *n; i++)
{
if(tmp != s[i].point)
{
cnt++;
tmp = s[i].point;
}
if(s[i].num < )
map[-s[i].num-][] = cnt;
else
map[s[i].num-][] = cnt;
}
init(, cnt, );
for(i = ; i < n; i++)
insert(, map[i][], map[i][], i+);
memset(f, , sizeof(f));
ans = ;
solve();
printf("%d\n",ans);
}
return ;
}
poj 2528 Mayor's posters(线段树)的更多相关文章
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- poj 2528 Mayor's posters 线段树区间更新
Mayor's posters Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...
- POJ 2528 Mayor's posters (线段树)
题目链接:http://poj.org/problem?id=2528 题目大意:有一个很上的面板, 往上面贴海报, 问最后最多有多少个海报没有被完全覆盖 解题思路:将贴海报倒着想, 对于每一张海报只 ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- POJ 2528 Mayor's posters (线段树+离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions:75394 Accepted: 21747 ...
- POJ 2528 Mayor’s posters (线段树段替换 && 离散化)
题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 ...
随机推荐
- Notes of the scrum meeting(2013/10/23)
ps:本来是10月23号周三下午开的会,这几天由于各种事情忙,忘记写博客了,现在补上. 软工项目组buaa_smile开始项目第一次scrum meeting meeting time:4:00~5: ...
- KVM通过qemu实现USB重定向
KVM是通过qemu来支持USB设备的,可以在启动的时候就指定需要连接的USB设备,也可以系统启动后动态的添加删除.通过qemu的help可知,使用qemu的usb_add host:xxx:xxx来 ...
- 【HDOJ】【3853】LOOPS
概率DP/数学期望 kuangbin总结中的第7题 其实跟UVA 11762 Race To 1 那道题差不多……直接推下公式,然后倒推即可 Trick:有的点可能是p1[i][j]==1……这样的点 ...
- 基于Hash算法的高维数据的最近邻检索
一.摘要 最紧邻检索:一种树基于树结构,一种是基于hash a.随机投影算法,需要产生很多哈希表,才能提高性能. b.基于学习的哈希算法在哈希编码较短时候性能不错,但是增加编码长度并不能显著提高性能. ...
- phonegap/cordova 启动页面
启动phonegap应用时,因为phonegap还在加载一系列的东西,总会出现一段时间的黑屏.解决方法是设置一个启动页面(闪屏)来过渡,让应用的用户体验更好一些. 先讲ios版本的: 首先,你需要准备 ...
- Java学习第七篇:与运行环境交互
目录 一.与用户互动 1.main方法形参 2.使用Scanner类获取输入 3.使用BufferedReader类获取输入 二.常用类 1.System类和Runtime类 2.String, St ...
- jquery层居中,点击小图查看大图,弹出层居中代码
1.层居中 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- PHPer 为什么会被 Javaer 鄙视?
最近看了知乎上的一个话题 「在工作中,为什么 Java 程序员常常瞧不起 PHP 程序员?」 个人从业多年,用过的后端语言 ASP.ASP.NET.Java.PHP.Node.js.Python,如果 ...
- Public, Private and Protect
public 意味着在其后声明的所有成员对所有的人都可以取. private 意味着除了该类型的创建者和类的内部成员函数之外,任何人都不能存取这些成员. protect 它与private基本相似,只 ...
- [转]剖析ASP.Net MVC Application
http://www.cnblogs.com/errorif/archive/2009/02/13/1389927.html 为了完全了解Asp.net MVC是怎样工作的,我将从零开始创建一个MVC ...