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 这个题目要倒着来写,从后面往前面贴,因为前面的有些会被后面的覆盖. 所以我们就判断这张海报的位置有没有完全被覆盖,如果完全被覆盖了就不能贴 ...
随机推荐
- 前端css3样式前缀自动补全工具--autoprefixer
最近在学习一份来自git的动画框架源码,看懂70%的核心代码后,打算自己动手实践一版,然鹅,所有框架搭起来以后,在动画这块却出了问题: 想设计一个slideInLeft的动画,必然想到了要从偏移-10 ...
- 原生开发之css样式问题(持续更新)
·移动端开发将div高度设置为设备高度 div{ Height:100vh; } · select选择器文字设置: /*select文字右对齐*/ select{ direction: rtl; } ...
- 简说JAVA8引入函数式的问题
JAVA8中加入lambda演算是一个令人兴奋的新特性——虽然这个新特性来得太迟了,目前的主流开发语言中,JAVA似乎是最后一个支持函数式思维的语言. 虽然晚了点,但总比没有好——况且我认为它的实现还 ...
- vb 案例学习
' ================================================================================================== ...
- leetcode_919. Complete Binary Tree Inserter
https://leetcode.com/problems/complete-binary-tree-inserter/ 设计一个CBTInserter,使用给定完全二叉树初始化.三个功能; CBTI ...
- 微擎we7模块和模板安装方法
2017年06月08日 09:26:55 源码学习分享 阅读数:15643 标签: we7 更多 个人分类: 微擎we7 版权声明:本文为博主原创文章,未经博主允许不得转载. https://bl ...
- opencv实现人脸,人眼,微笑检测
1.首先实现人脸检测 import cv2 img = cv2.imread("people.jpg",1) #读入图像 #导入人脸级联分类器引擎,“.xml”文件里包含了训练出来 ...
- c++ 模板template
1.函数模板的声明 声明形式 template<typename 数据类型参数标识符> <返回类型><函数名>(参数表) { 函数体 } 注: templa ...
- 1434:【例题2】Best Cow Fences
1434:[例题2]Best Cow Fences 时间限制: 1000 ms 内存限制: 65536 KB提交数: 263 通过数: 146 [题目描述] 给定一个长度为n的 ...
- 【计算机网络】3.2 无连接运输:UDP
第三章第二节 无连接运输:UDP UDP(用户数据报协议,User Datagram Protocol),它只是做了运输层协议能够做的最少工作,除了多路复用和多路分解及一些差错检测外,它几乎没有做任何 ...