Mayor's posters
Description
- 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
/*
题意:给横坐标轴染色,每次给一个区间内的染色,每染一次会把上一次的覆盖,经过n次染色只会,问你从最上面看,横坐标上总共有几种颜色 初步思路:区间染色问题,就是一个区间set问题,然后最后的查询的时候,记录一下就行了 #超内存:需要离散化
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int n,l[],r[];
int t;
bool color[];//用于记录颜色
int res=;
int X[];
int k;
int kk;
/****************************线段树基础模板*********************************/ const int maxn=+;
#define lson i*2, l, m
#define rson i*2+1, m+1, r struct Segtree{ int setv[maxn<<]; void PushDown(int i)
{
if(setv[i]>){
setv[i*]=setv[i*+]=setv[i];
setv[i]=-;//向下更新完了就没有继续用的意义了
}
} void build(int i,int l,int r)
{
// cout<<l<<" "<<r<<" "<<i<<endl;
setv[i]=;
if(l==r)
return ;
int m=(l+r)>>;
build(lson);
build(rson);
}
void query(int ql,int qr,int i,int l,int r)
{
if(ql<=l&&r<=qr){
if(setv[i]>){
color[setv[i]]=true;
return ;
}
}
if(l==r) return ;
PushDown(i);
int m=(l+r)>>;
if(ql<=m) query(ql,qr,lson);
if(m<qr) query(ql,qr,rson);
} void update(int ql,int qr,int val,int i,int l,int r)
{
// cout<<l<<" "<<r<<endl;
if(ql<=l&&r<=qr)
{
setv[i]=val;
return ;
}
PushDown(i);
int m=(l+r)>>;
if(ql<=m) update(ql,qr,val,lson);
if(m<qr) update(ql,qr,val,rson);
}
};
Segtree segtree;
/****************************线段树基础模板*********************************/
void init(){
memset(color,false,sizeof color);
res=;
k=;
kk=;
}
int findx(int key){
int l=,r=k,mid;
while(l<=r){
mid=(l+r)>>;
if(X[mid]==key)
return mid;
else if(X[mid]>key)
r=mid-;
else l=mid+;
}
return ;
}
int main(){
// freopen("in.txt","r",stdin);
scanf("%d",&t);
while(t--){
init();
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%d",&l[i],&r[i]);
X[kk++]=l[i];
X[kk++]=r[i];
}
sort(X+,X+kk+);
for(int i=;i<kk;i++){//离散化
if(X[i]!=X[i-])
X[++k]=X[i];
}
segtree.build(,,k);
for(int i=;i<=n;i++){
int L=findx(l[i]);
int R=findx(r[i]);
segtree.update(L,R,i,,,k);
}
segtree.query(,k,,,k);
for(int i=;i<=n;i++){
if(color[i]) res++;
}
printf("%d\n",res);
}
return ;
}
5
1 4
2 6
8 10
3 4
7 10
Sample Output
4
Mayor's posters的更多相关文章
- POJ 2528 Mayor's posters
Mayor's posters Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- 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, 如果利用线段树求解的话,很明显 ...
- POJ 2528 Mayor's posters(线段树/区间更新 离散化)
题目链接: 传送门 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Description The citizens of By ...
- Mayor's posters(线段树+离散化POJ2528)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51175 Accepted: 14820 Des ...
- poj2528 Mayor's posters(线段树之成段更新)
Mayor's posters Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 37346Accepted: 10864 Descr ...
- POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59239 Accepted: 17157 ...
- poj-----(2528)Mayor's posters(线段树区间更新及区间统计+离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 43507 Accepted: 12693 ...
- Poj 2528 Mayor's posters 分类: Brush Mode 2014-07-23 09:12 84人阅读 评论(0) 收藏
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40570 Accepted: 11798 ...
- POJ 2528 Mayor’s posters
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37982 Accepted: 11030 ...
随机推荐
- SpringBoot文档翻译系列——29.SQL数据源
原创作品,可以转载,但是请标注出处地址: 因为需要使用到这方面内容,所有对这一部分进行了翻译. 29 使用SQL数据源 SpringBoot为SQL数据源提供了广泛支持,从直接使用JdbcTempl ...
- Pro Flight YOKE 设备键位映射踩过的坑
背景 VR游戏项目.街机游戏项目7月阶段版本快要结束了,考虑到带有键鼠外设显得逼格比较Low,所以决定采用"高大上"的专业设备来进行游戏操作. 需求 需要将键盘鼠标操作的18个键位 ...
- 从头编写 asp.net core 2.0 web api 基础框架 (1)
工具: 1.Visual Studio 2017 V15.3.5+ 2.Postman (Chrome的App) 3.Chrome (最好是) 关于.net core或者.net core 2.0的相 ...
- 兼容低版本JS的Array.map方法
前几天去别的公司面试遇到个这样的问题,兼容IE7下的Array.map方法,一脸蒙蔽.后面回来查了下资料发现.Array.map方法是ECMA-262 标准中新添加的方法,在低版本的JS中是木有的. ...
- HDU1085 多重背包
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- 扩展jquery.validate自定义验证,自定义提示,本地化
<!DOCTYPE html> <html> <head> <meta name="viewport" content="wid ...
- 学习总结---OVS
OVS的组成 OVS的匹配条件和动作 OVS的发展方向 OVS的实践 OVS与Namespace配合模拟租户之间的数据通信 基本思路: Namespace模拟出不同的主机,这些主机之间的通信需要通过S ...
- win10 uwp InkCanvas控件数据绑定
本文主要说如何绑定InkCanvas,让笔画变化的时候我们可以知道. 我们本来的InkCanvas没有提供笔画绑定,所以我们自己写 using Windows.UI.Input.Inking; usi ...
- 关于限制DHCP服务器广播的另类方法
0. 引言 如图,家里有两台计算机,分别处于不同房间.其中一台PC1能够与光猫直连:另外一台PC2较远,考虑到光猫有WLAN功能,便使用了一个路由器无线桥接到光猫,然后有线连接到PC2(均与光猫处于同 ...
- HTML5之indexedDB
从陌生到了解,花了一下午的时间,以下的地址还是不错的参考资料,省的到处去找 HTML5本地存储——IndexedDB(一:基本使用) 官方API接口文档 官方使用示例 html5 初试 indexed ...