Description

  The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for placing the posters and introduce the following rules:

  • 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. 

 
  题目大致就是说给一个线段覆盖线段,问最后没有被完全覆盖的线段的个数。
  这是第一次写离散,也是第三次写线段树的区间更新,想了好久,发现是个空线段树,只需要COL,即标记,不需要BIT来保存啥数据。
  离散的话是因为数据范围太大,只取用到的,排序后分别编号为1...N ,再用。
  (注:这个题要注意,离散的话比如3和7分别标号为4和5的话,那么如果第一个覆盖1-20,第二个覆盖1-3 , 另一个覆盖 7-10 的话,那么编号4和5都被覆盖,结果将为2,而不是正确的3 。 所以可以按照杭电那位大神的处理方法,只要3和7之间超过1,那么再加一个数4,这样的话分别编号为4,5,6就好了。)
  标记记录每次更新的为编号几。
 
代码如下:
#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 , 离散+线段树。的更多相关文章

  1. poj 2528 Mayor's posters(线段树+离散化)

    /* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 ...

  2. POJ 2528——Mayor's posters——————【线段树区间替换、找存在的不同区间】

    Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  3. POJ 2528 Mayor's posters(线段树区间染色+离散化或倒序更新)

    Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59239   Accepted: 17157 ...

  4. POJ 2528 Mayor's posters(线段树/区间更新 离散化)

    题目链接: 传送门 Mayor's posters Time Limit: 1000MS     Memory Limit: 65536K Description The citizens of By ...

  5. POJ 2528 ——Mayor's posters(线段树+区间操作)

    Time limit 1000 ms Memory limit 65536 kB Description The citizens of Bytetown, AB, could not stand t ...

  6. POJ 2528 Mayor's posters(线段树)

    点我看题目 题意 :建一堵墙粘贴海报,每个候选人只能贴一张海报,海报的高度与墙一样高,一张海报的宽度是整数个单位,墙被划分为若干个部分,每个部分的宽度为一个单位,每张海报完全的覆盖一段连续的墙体,墙体 ...

  7. POJ 2528 Mayor's posters(线段树染色问题+离散化)

    http://poj.org/problem?id=2528 题意: 给出一面无限长的墙,现在往墙上依次贴海报,问最后还能看见多少张海报. 题意:这道题目就相当于对x轴染色,然后计算出最后还能看见多少 ...

  8. POJ:2528(Mayor's posters)离散化成段更新+简单哈希

    http://poj.org/problem?id=2528 Description The citizens of Bytetown, AB, could not stand that the ca ...

  9. 【POJ】2528 Mayor's posters ——离散化+线段树

    Mayor's posters Time Limit: 1000MS    Memory Limit: 65536K   Description The citizens of Bytetown, A ...

随机推荐

  1. 【转】Java 内部类种类及使用解析

    Java 内部类种类及使用解析 内部类Inner Class 将相关的类组织在一起,从而降低了命名空间的混乱. 一个内部类可以定义在另一个类里,可以定义在函数里,甚至可以作为一个表达式的一部分. Ja ...

  2. Swift --> Map & FlatMap

    转载自:https://segmentfault.com/a/1190000004050907 Map map函数能够被数组调用,它接受一个闭包作为参数,作用于数组中的每个元素.闭包返回一个变换后的元 ...

  3. setter getter 属性 点语法

    转载自:http://liuyafang.blog.51cto.com/8837978/1543715 什么时setter,getter, 在OC里, 为实例变量赋zhi的方法称作setter(设置器 ...

  4. SQL Server 自定义快捷键

    SQL Server程序员经常要在SSMS(SQL Server Management Studio)或查询分析器(2000以前)中编写T-SQL代码.以下几个技巧,可以提升工作效率. 以下说明以SS ...

  5. HDU 1681 Frobenius(完全背包+标记装满)

    一个完全背包,数组两百万,暴力可过 #include<iostream> #include<cstdio> #include<cstring> using name ...

  6. struts2+ajax实现异步验证

    由于老师布置作业的需要,在添加管理员的时候,要实现验证添加的管理员的用户名是否在数据库中已经存在,然后再客户端给用户一个提示.我首先想到的就是利用ajax实现异步验证技术,由于利用的ssh框架,所以在 ...

  7. Android Screen Monitor使用

    Android Screen Monitor的使用 用来把android手机屏幕投射到电脑屏幕上,能够放大缩小屏幕,与手机屏幕保持同步. 这个项目是一个开源项目,源码地址:https://code.g ...

  8. java打jar包

    一.打包jar文件 1      如果是class文件     jar cvf myjar.jar Foo.class Bar.class 如果是包     jar cvf myjar.jar pac ...

  9. STM32片上Flash内存映射、页面大小、寄存器映射

    STM32片上Flash内存映射.页面大小.寄存器映射 STM32有4种Flash module organization,分别是:low-density devices(32KB,1KB/page) ...

  10. android app开发

    android 中文文档:   http://www.android-doc.com/training/index.html 二维码在线自动生成.http://www.liantu.com/