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 这个题目要倒着来写,从后面往前面贴,因为前面的有些会被后面的覆盖. 所以我们就判断这张海报的位置有没有完全被覆盖,如果完全被覆盖了就不能贴 ...
随机推荐
- poj3109 Inner Vertices
思路: 树状数组 + 扫描线. 实现: #include <cstdio> #include <vector> #include <algorithm> using ...
- js promise 介绍和使用
1.什么是promise js是单线程执行的. ajax是典型的异步操作,我们通常会在ajax的成功或者失败之后写上回掉函数.这中写法是一种嵌套的方式,如果回掉多了会造成代码复杂并且难以复用. pro ...
- 掌握Spark机器学习库-07-线性回归算法概述
1)简介 自变量,因变量,线性关系,相关系数,一元线性关系,多元线性关系(平面,超平面) 2)使用线性回归算法的前提 3)应用例子 沸点与气压 浮力与表面积
- 关于 Oracle 11g r2 Enterprise Manager (EM) 在windows环境无法启动的解决办法
正确的解决办法是在安装的时候使用emca正确安装 如果已经安装过Enterprise Manager: 请用是如下命令卸载后重装 emca -deconfig dbcontrol db emca -r ...
- Relational Algebra 关系代数
Relational Algebra Relational Algebra is the mathematical basis for the query language SQL Introduct ...
- MFC_简易文件管理器
练习_简易文件管理器 Edit1编辑框绑定变量,初始化内容 m_EditCtrl = L"D:\"; 添加List控件,属性设置report,OnInitDialog()函数里添加 ...
- Jmeter之WebService接口测试
一.简介 1.JMeter3.2前的版本,可以使用SOAP/XML-RPC Request插件直接进行webservice接口,而3.2后的版本则已经取消了这个接口,需要另外的方法才能进行测试. 2 ...
- A7. JVM 垃圾回收收集器(GC 收集器)
[概述] 如果说收集算法是内存回收的方法论,那么垃圾收集器就是内存回收的具体实现.Java 虚拟机规范中对垃圾收集器应该如何实现没有任何规定,因此不同的厂商.不同版本的虚拟机所提供的垃圾处理器都可能会 ...
- bootstrap-table的一些基本使用及表内编辑的实现
最近工作需要接触了bootstrap-table 所以研究了一下,并做了笔记,红色位置要特别注意 前端主要使用了 jquery bootstrap-table bootstrap-edittable ...
- 微信小程序UI组件库 iView Weapp快速上手
概述 今天在网上突然看到iView新出了一个微信小程序的组件库iView Weapp,自己就上手试了一下,发现用起来还是不错的,把自己使用的过程与大家分享下. 一 预览iView组件 1.可以在手机上 ...