线段树 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 ...
随机推荐
- AJPFX关于延迟加载的单例模式的安全问题解决
请写一个延迟加载的单例模式?写懒汉式:当出现多线程访问时怎么解决?加同步,解决安全问题:效率高吗?不高:怎样解决?通过双重判断的形式解决.懒汉式:延迟加载方式.当多线程访问懒汉式时,因为懒汉式的方法内 ...
- uvm_transaction——事物
文件: src/base/uvm_transaction.svh 类: uvm_transaction uvm_transaction继承自uvm_object,添加了timing和record ...
- nagios的安装配置
主要参考博客:http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html 实验环境:centos6.4 最小化安装系统 **** ...
- windows Git的安装和使用
一.本人是根据廖雪峰大神的个人官网学习的git,并有感而发以做笔记的方式写下这篇博客,希望可以帮助到自己和其他人,廖雪峰个人官网http://www.liaoxuefeng.com/ 二.声明我的电脑 ...
- Azure School女神相邀,把每分钟都过的更充实
也许你不姓「牛」,但是你技术牛啊 所以,请容我叫你一声「牛郎」 (讲真,只是因为你技术牛,不是其他啥原因哈) 平时忙到昏天黑地,一心一意为技术的你 注意看一下日历,因为: !!!七夕节(8月28日)到 ...
- iOS面试题 第一天
今天上午,下午分别面试了两家公司.上午是一家互联网公司,气氛还比较好,是我比较喜欢的.技术这块是直接机试,主要是给了些BUG让我修复,整个过程还算顺利.下午去了一家大型的证券公司.整理技术问题如下: ...
- bfs染色法判定二分图
#include<iostream> #include<queue> #include<cstring> #include<cstdio> using ...
- CentOS7——防火墙设置
1.查看firewall服务状态 systemctl status firewalld 2.查看firewall的状态firewall-cmd --state 3.开启.重启.关闭.firewalld ...
- 1658: Easier Done Than Said?
1658: Easier Done Than Said? Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 15 Solved: 12[Submit][St ...
- OpenCV2:第八章 界面事件
一.简介 OpenCV中提供了程序界面中的鼠标和键盘事件 二.鼠标事件 // 设置鼠标回调函数 void setMouseCallback ( const string& winname, ...