线段树 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 ...
随机推荐
- hihocoder1860 最大异或和
思路: 把N个前缀异或和插入一棵trie树中,然后对每个前缀异或和x计算能使x ^ y最大的前缀异或和y.利用了异或运算的a ^ b ^ a = b的性质. 参考了https://cloud.tenc ...
- JS小游戏
捕鱼达人 飞机大战游戏 详解javaScript的深拷贝 http://www.cnblogs.com/penghuwan/p/7359026.html
- Objective-C Log Handling
NSLog method In order to print logs, we use the NSLog method in Objective-C programming language whi ...
- ycsb安装和使用介绍
nosql性能测试工具ycsb0.1的使用 使用文档参考地址:https://www.cnblogs.com/SailorXiao/p/5808828.html ycsb地址:https://gith ...
- shell流程语句使用介绍
1)使用if.case.read例子1:#!/bin/bash#读取终端输入的字符read -p "Please input a Number:" nn1=`echo $n|sed ...
- 洛谷 P1734 最大约数和
题目描述 选取和不超过S的若干个不同的正整数,使得所有数的约数(不含它本身)之和最大. 输入输出格式 输入格式: 输入一个正整数S. 输出格式: 输出最大的约数之和. 输入输出样例 输入样例#1: 1 ...
- SQLite-表达式
SQLite -表达式 一个表达式是一个或多个值的组合,运算符和SQL函数,评价一个值. SQL表达式就像公式和都写在查询语言.您还可以使用为特定的数据集查询数据库. 语法: 考虑到SELECT语句的 ...
- java中的堆与栈
Java 中的堆和栈 Java把内存划分成两种:一种是栈内存,一种是堆内存. 在函数中定义的一些基本类型的变量和对象的引用变量都在函数的栈内存中分配 . 当在一段代码块定义一个变量时,Java就在栈中 ...
- iOS面试题 第一天
今天上午,下午分别面试了两家公司.上午是一家互联网公司,气氛还比较好,是我比较喜欢的.技术这块是直接机试,主要是给了些BUG让我修复,整个过程还算顺利.下午去了一家大型的证券公司.整理技术问题如下: ...
- js 上传图片
<div class="block-input" style="height: 90px"> <span><i class=&qu ...