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
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
typedef long long LL;
const int MAXN = ;
struct post
{
LL l,r;
}p[MAXN];
int x[MAXN<<];
int H[];
struct node
{
LL l,r;
bool laz;//标记当前是否被完全覆盖
}T[MAXN*+]; void pushup(LL p)
{
if(T[p*].laz&&T[p*+].laz)
T[p].laz = true;
/*else
T[p].laz = false;*/
}
void build(LL p,LL l,LL r)
{
T[p].l = l,T[p].r = r;
T[p].laz = false;
if(l==r) return ;
int mid = (l + r)/;
build(p*,l,mid);
build(p*+,mid+,r);
}
bool update(LL x,LL l,LL r)
{
if(T[x].laz) return false;
if(l == T[x].l && r == T[x].r)
{
T[x].laz = true;
return true;
}
//pushdown(x);
LL mid = (T[x].l + T[x].r)/;
bool R;
if(r<=mid)
R = update(x*,l,r);
else if(l>mid)
R = update(x*+,l,r);
else
{
bool r1 = update(x*,l,mid);
bool r2 = update(x*+,mid+,r);
R = r1||r2;
}
if(T[x*].laz&&T[x*+].laz)
T[x].laz = true;
return R;
}
int main()
{
int n;
int T;
scanf("%d",&T);
while(T--)
{
int cnt = ;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&p[i].l,&p[i].r);
x[cnt++] = p[i].l;
x[cnt++] = p[i].r;
}
sort(x,x+cnt);
cnt = unique(x,x+cnt)-x;
for(int i= ;i<cnt;i++)
H[x[i]] = i;
build(,,cnt-);
int ans = ;
for(int i = n-; i>=; i--)
if(update(,H[p[i].l],H[p[i].r]))
ans++;
printf("%d\n", ans);
}
}
Mayor's posters POJ - 2528的更多相关文章
- Mayor's posters POJ - 2528(线段树 + 离散化)
		
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 74745 Accepted: 21574 ...
 - (线段树)Mayor's posters --poj -- 2528
		
链接: http://poj.org/problem?id=2528 覆盖问题, 要从后往前找, 如果已经被覆盖就不能再覆盖了,否则就可以覆盖 递归呀递归什么时候我才能吃透你 代码: #include ...
 - D - Mayor's posters POJ - 2528  离散化+线段树 区间修改单点查询
		
题意 贴海报 最后可以看到多少海报 思路 :离散化大区间 其中[1,4] [5,6]不能离散化成[1,2] [2,3]因为这样破坏了他们的非相邻关系 每次离散化区间 [x,y]时 把y+1点也加入 ...
 - Mayor's posters POJ - 2528 线段树区间覆盖
		
//线段树区间覆盖 #include<cstdio> #include<cstring> #include<iostream> #include<algori ...
 - Mayor's posters POJ - 2528 线段树(离散化处理大数?)
		
题意:输入t组数据,输入n代表有n块广告牌,按照顺序贴上去,输入左边和右边到达的地方,问贴完以后还有多少块广告牌可以看到(因为有的被完全覆盖了). 思路:很明显就是线段树更改区间,不过这个区间的跨度有 ...
 - 线段树 Mayor's posters
		
甚至DFS也能过吧 Mayor's posters POJ - 2528 The citizens of Bytetown, AB, could not stand that the candidat ...
 - D - Mayor's posters
		
D - Mayor's posters POJ - 2528 思路:线段树+离散化. 离散化时注意特殊情况,如果两个数相差大于一,离散时也应该差1.比如 1 3 离散后应该为 1 2. 错因: 1.二 ...
 - poj 2528 线段树区间修改+离散化
		
Mayor's posters POJ 2528 传送门 线段树区间修改加离散化 #include <cstdio> #include <iostream> #include ...
 - 线段树 G - Mayor's posters 小技巧
		
G - Mayor's posters POJ - 2528 这个题目要倒着来写,从后面往前面贴,因为前面的有些会被后面的覆盖. 所以我们就判断这张海报的位置有没有完全被覆盖,如果完全被覆盖了就不能贴 ...
 
随机推荐
- 桥接模式和php实现
			
桥接模式(Bridge Pattern): 将抽象部分与它的实现部分分离,使它们都可以独立地变化.它是一种对象结构型模式,又称为柄体(Handle and Body)模式或接口(Interface)模 ...
 - 解决webstromm标签高亮问题
			
2017/2016版
 - ESSENTIALS OF PROGRAMMING LANGUAGES (THIRD EDITION) :编程语言的本质 —— (一)
			
# Foreword> # 序 This book brings you face-to-face with the most fundamental idea in computer prog ...
 - spring-mvc hello world    (1)
			
我学习一个程序,都是从DEMO开始的. 先不了解SPRING-MVC的原理,但一些小的概念还是需要了解的.由于之前有过SSH的工程经验,故基本的东东,不在叙述. 1.准备环境 JAR包:
 - DBUtils使用技巧
			
BbUtils(一) 结果集概览:http://www.cnblogs.com/myit/p/4269165.html DbUtils(二) 结果集实例:http://www.cnblogs.com/ ...
 - MySQL基础、索引、查询优化等考察点
			
MySQL基础 MySQL数据类型 整数类型 TINYINT. SMALLINT. MEDIUMINT. INT. BIGINT 属性:UNSIGNED 长度:可以为整数类型指定宽度,例如:INT(1 ...
 - CAD参数绘制实心圆弧填充(网页版)
			
js中实现代码说明: function DrawPathToHatch1() { //把路径的开始位置移动指定的点 //参数一为点的X坐标 ,参数二为点的Y坐标,参数三为该点处开始宽度,对Polyli ...
 - js 异步提交文件
			
<form method="POST" action="${ctx}/statement/manage/upload" name="form&q ...
 - P1387 最大正方形&&P1736 创意吃鱼法
			
P1387 最大正方形 P1736 创意吃鱼法 两道类似的$DP$ 转移方程基本上类似于$f[i][j]=min(f[i-1][j-1],min(f[i][j-1],f[i-1][j]))$ 考虑构成 ...
 - 自动下载相对应的jar包
			
一.去到需要的 maven下载地址 http://mvnrepository.com/artifact/org.apache.struts/struts2-core/2.5.13 二.然后去到 pom ...