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 socket通信演示以及socket操作类
准备做Java的课程设计,一个通讯录.采用C/S架构.客户端用java FX和Java,服务器端用php,采用socket通信. 下面来讲一讲php的socket通信: 讲之前,得先讲一下TCP/IP ...
- Objective-C Memory Management 内存管理 2
Objective-C Memory Management 内存管理 2 2.1 The Rules of Cocoa Memory Management 内存管理规则 (1)When you c ...
- iTOP-4418开发板最新资料及例程
开发板资料: 开发板硬件资源: 1.POWER电源接口 电源输入为 5V/2A+,给核心板 AXP228 电源管理芯片提供 5V 电源. 2.SWITCH电源开关 轻触电源开关可以控制开发板电源通断. ...
- biff - 新到邮件提醒
总览 (SYNOPSIS) biff [ny ] 描述 (DESCRIPTION) Biff 通知系统在当前终端会话期间有新邮件是否提醒你. 支持的选项有 biff n 禁止新邮件提醒. y 开启新邮 ...
- 关于TreeView控件的TreeNodeCheckChanged事件无法回发处理
1.在后台设置属性 TreeView1.Attributes.Add("onclick", "postBackByObject()"); 2.在前台页面中间添加 ...
- CAD参数绘制实心圆弧填充(com接口)
C#中实现代码说明: private void DrawPathToHatch1() { //把路径的开始位置移动指定的点 //参数一为点的X坐标 ,参数二为点的Y坐标,参数三为该点处开始宽度,对Po ...
- Java基础(十一)--Serializable和Externalizable接口实现序列化
序列化在日常开发中经常用到,特别是涉及到网络传输的时候,例如调用第三方接口,通过一个约定好的实体进行传输,这时你必须实现序列 化,这些都是大家都了解的内容,所以文章也会讲一下序列化的高级内容. 序列化 ...
- vue-cli 中使用less
(1)安装Less模块: npm install less (2)安装less和less-loader,命令如下 npm install less less-loader --sava-dev (3) ...
- Perl语言入门:第六章习题:处理用户所指定的名字并汇报相应的姓。
37 print "\n----------------------------------_exercise_6_1--------------------------\n"; ...
- my @unpacking_list = values %map_function; print "\n".@unpacking_list; 输出是3 把 @unpacking_list 当做一个数 输出了
my %map_function = ( 88 "OK_func" => "open_statement", 89 & ...