线段树 Mayor's posters
甚至DFS也能过吧
Mayor's posters POJ - 2528
- Every candidate can place exactly one poster on the wall.
- All posters are of the same height equal to the height of the wall; the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown).
- The wall is divided into segments and the width of each segment is one byte.
- Each poster must completely cover a contiguous number of wall segments.
They have built a wall 10000000 bytes long (such that there is enough place for all candidates). When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width. Moreover, the candidates started placing their posters on wall segments already occupied by other posters. Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections.
Your task is to find the number of visible posters when all the posters are placed given the information about posters' size, their place and order of placement on the electoral wall.
Input
Output
The picture below illustrates the case of the sample input.
Sample Input
1
5
1 4
2 6
8 10
3 4
7 10
Sample Output
4
kuangbing专题也放了这道题,确实是比较经典的线段树,但是这个还没2有涉及到修改操作
sort+lower_bound+unique离散下
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N=;
int b[N<<],a[N<<][],bj[N<<],M,H,bn;
int T[N*];
void built(int n) {
H=;
for(int i=; i<n+; i<<=)H++;
M=<<H;
for(int i=; i<=M<<; i++) T[i]=;
for(int i=; i<=n; i++)bj[i]=;
}
void update(int l,int r,int val) {
for(l=l+M-,r=r+M+;l^r^;l>>=,r>>=) {
if(~l&)T[l^]=val;
if(r&)T[r^]=val;
}
}
void query(int pos) {
int ans=;
for(int i=pos+M; i>; i>>=)
ans=max(ans,T[i]);
bj[ans]=;
}
int main() {
int t,n;
scanf("%d",&t);
while(t--) {
bn=;
scanf("%d",&n);
for(int i=; i<=n; i++) {
scanf("%d%d",&a[i][],&a[i][]);
b[++bn]=a[i][];
b[++bn]=a[i][];
}
sort(b+,b+bn+);
bn=unique(b+,b+bn+)-b-;
built(bn);
for(int i=; i<=n; i++) {
int l=lower_bound(b+,b+bn+,a[i][])-b;
int r=lower_bound(b+,b+bn+,a[i][])-b;
update(l,r,i);
}
int ans=;
for(int i=; i<=bn; i++) query(i);
for(int i=; i<=bn; i++) if(bj[i])ans++;
printf("%d\n",ans);
}
return ;
}
线段树 Mayor's posters的更多相关文章
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- poj 2528 Mayor's posters(线段树+离散化)
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...
- Mayor's posters(线段树+离散化POJ2528)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51175 Accepted: 14820 Des ...
- poj-----(2528)Mayor's posters(线段树区间更新及区间统计+离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 43507 Accepted: 12693 ...
- 【POJ】2528 Mayor's posters ——离散化+线段树
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Description The citizens of Bytetown, A ...
- Mayor's posters(离散化线段树)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 54067 Accepted: 15713 ...
- 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: 1000MS Memory Limit: 65536K Total Submissions:75394 Accepted: 21747 ...
- Mayor's posters POJ - 2528(线段树 + 离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 74745 Accepted: 21574 ...
随机推荐
- React 实践记录 04 Flux demo
Introduction flux应用架构如下图所示,本文并不是讲述怎么立即做一个酷炫的应用,而是讲述如何依照这种框架,来进行代码的组织. 我们先把这个流程转述为文字:抛开与webAPI的交互不谈,以 ...
- NSTimer 实现时钟回调方法
在开发过程中,发现时钟调用的地方比较多.所以对时钟进行了一个简单的统一封装.具体代码如下: 1.时钟回调函数的声明: #pragma mark 时钟回调处理 //时钟回调 +(NSTimer*) ls ...
- ListView与ScrollView冲突的4种解决方案
问题解决方案1.手动设置ListView高度 经过测试发现,在xml中直接指定ListView的高度,是可以解决这个问题的,但是ListView中的数据是可变的,实际高度还需要实际测量.于是手动 ...
- java.lang.IllegalArgumentException: name MUST NOT NULL! at org.nutz.dao.impl.NutDao.fetch
Nutz传值报错问题 作者:Vashon 时间:20150902 平台:Nutz框架 Java后台方法中拿值时报的错 报错信息: java.lang.IllegalArgumentException: ...
- xcode或者mac自带颜色器选择rgb格式
解决方法
- Hibernate查询方式汇总
Hibernate总的来说共有三种查询方式:HQL.QBC和SQL三种.但是细分可以有如下几种: 一.HQL查询方式 这一种我最常用,也是最喜欢用的,因为它写起来灵活直观,而且与所熟悉的SQL的 ...
- 手把手教你打造一个 Mac 风格的 Windows10(手动滑稽)
Mark https://www.sqlsec.com/2018/04/winmac.html 大佬写得很好,资瓷!! MyDock可能不是最新的,给出官方维护的网盘:https://pan.bai ...
- 理解Vue
Vue.js是JavaScript MVVM(Model-View-ViewModel)库,十分简洁,Vue核心只关注视图层,相对AngularJS提供更加简洁.易于理解的API.Vue尽可能通过简单 ...
- flex常用属性
<1>align-items: 垂直方向的对齐方式 align-items: stretch(拉伸,布满父容器) | center(垂直居中) | flex-start(上对齐) | fl ...
- jdk concurrent 中 AbstractQueuedSynchronizer uml 图.
要理解 ReentrantLock 先理解AbstractQueuedSynchronizer 依赖关系. 2