(中等) POJ 2528 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.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring> #define lson L,M,po*2
#define rson M+1,R,po*2+1 using namespace std; int COL[*];
int num[];
int num1[];
int rnum[];
int cou;
bool vis[]; int findH(int x,int L,int R)
{
int M=(L+R)/; if(rnum[M]==x)
return M; if(rnum[M]<x)
return findH(x,M+,R);
else
return findH(x,L,M);
} void pushDown(int po)
{
if(COL[po])
{
COL[po*]=COL[po];
COL[po*+]=COL[po]; COL[po]=;
}
} void update(int ul,int ur,int cha,int L,int R,int po)
{ if(ul<=L&&ur>=R)
{
COL[po]=cha; return;
} pushDown(po); int M=(L+R)/; if(ul<=M)
update(ul,ur,cha,lson);
if(ur>M)
update(ul,ur,cha,rson); } void query(int L,int R,int po)
{
if(L==R)
{
if(COL[po])
vis[COL[po]]=; return;
} pushDown(po); int M=(L+R)/; query(lson);
query(rson);
} int main()
{
int T,N;
int a,b;
int ans=;
cin>>T; while(T--)
{
memset(COL,,sizeof(COL));
memset(vis,,sizeof(vis));
scanf("%d",&N); ans=; for(int i=;i<N;++i)
{
scanf("%d %d",&num[i*],&num[i*+]);
num1[i*]=num[i*];
num1[i*+]=num[i*+];
} sort(num,num+*N); rnum[]=num[];
cou=;
for(int i=;i<N*;++i)
{
if(num[i]==num[i-])
continue; if(num[i]-num[i-]>)
rnum[cou++]=num[i-]+; rnum[cou++]=num[i];
} for(int i=;i<N;++i)
{
a=findH(num1[i*],,cou-);
b=findH(num1[i*+],,cou-); update(a+,b+,i+,,cou,);
} query(,cou,); for(int i=;i<=N;++i)
if(vis[i])
++ans; printf("%d\n",ans);
} return ;
}
(中等) POJ 2528 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:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- 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 Description The citizens of By ...
- POJ 2528 ——Mayor's posters(线段树+区间操作)
Time limit 1000 ms Memory limit 65536 kB Description The citizens of Bytetown, AB, could not stand t ...
- POJ 2528 Mayor's posters(线段树)
点我看题目 题意 :建一堵墙粘贴海报,每个候选人只能贴一张海报,海报的高度与墙一样高,一张海报的宽度是整数个单位,墙被划分为若干个部分,每个部分的宽度为一个单位,每张海报完全的覆盖一段连续的墙体,墙体 ...
- POJ 2528 Mayor's posters(线段树染色问题+离散化)
http://poj.org/problem?id=2528 题意: 给出一面无限长的墙,现在往墙上依次贴海报,问最后还能看见多少张海报. 题意:这道题目就相当于对x轴染色,然后计算出最后还能看见多少 ...
- POJ:2528(Mayor's posters)离散化成段更新+简单哈希
http://poj.org/problem?id=2528 Description The citizens of Bytetown, AB, could not stand that the ca ...
- 【POJ】2528 Mayor's posters ——离散化+线段树
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Description The citizens of Bytetown, A ...
随机推荐
- opencv---cvor
void cvXor计算两个数组中的每个元素的按位异或. void cvXor (const CvArr* src1, const CvArr* src2, CvArr* dst, const CvA ...
- Trie/最短的名字
题目链接 /* 简单trie树的应用,注意在初始化的时候要把cnt也初始化,不然,WA! 下面的四分代码各有特点 */ //数组型,名字查询. #include<cstdio> #incl ...
- Lucene add、updateDocument添加、更新与search查询(转)
package com.lucene; import java.io.IOException; import org.apache.lucene.analysis.standard.Stand ...
- oracle 基础使用以及sql语句基础
oracle的安装与卸载 要记住数据库口令,适用于sys.system.sysman/dbsnmp等账户,而scott帐号密码默认为tiger, 以oracle 10g来说,scott账户默 ...
- UVALive 4031 Integer Transmission(贪心 + DP)
分析:求出最大值和最小值比较简单,使用贪心法,求最小值的时候我们让所有的0尽可能的向后延迟就可以了,求最大值则相反. 关键在于求出可以组合出的数字个数. 这就是组合数学版的dp了,我们让dp[i][j ...
- $.ajax和$.post的区别(前者根据key-value/后者根据形参)
post不需要给key-value形式: $("#btn").click(function(){ var url=basePath+"/emp/login"; ...
- Servlet程序开发--取得初始化配置信息
代码: 两个初始化init方法,一起出现的话,有参的才起作用 package org.lxh.servletdemo ; import java.io.* ; import javax.servlet ...
- JSP文件上传--FileUpload组件
如果使用上传操作,并且没有使用框架之类,最好使用Smartupload,因为FileUpdate太难使用. 下载组件: fileupload包:http://commons.apache.org/pr ...
- 9、外观模式(Facade)
外观模式是为了解决类与类之家的依赖关系的,像spring一样,可以将类和类之间的关系配置到配置文件中,而外观模式就是将他们的关系放在一个Facade类中,降低了类类之间的耦合度,该模式中没有涉及到接口 ...
- Java socket通信
首先抛开语言层面,简单介绍一下socket通信过程: 1.服务器端开启监听端口,阻塞进程 等待客户端连接 2.客户端连接,这时就产生了一个socket socket就相当于一个传递消息的通道,一般都 ...