这个题意是市长竞选,然后每一个人都能够贴广告牌。能够覆盖别人的看最后剩几个广告牌

这题目想了两个多小时,最后忍不住看了一下题解。

发现仅仅是简单地hash  和线段树成段更新

由于有10000个人竞选。所以最多是10000个区间。20000个点,线段树就不会爆内存了。

详细操作有两个:

(1)哈希之后把每一个区间端点当做底层节点。而且仅仅要是把这个节点染色之后就是把这两个节点之中的全染色了

(2)简单地线段树更新

详情请见代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxx 20010
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int sum[maxx<<2];//建树
int num[maxx<<1];
int cnt;
int hash[maxx<<1];
int a[maxx],b[maxx];
void pushup(int rt)//更新节点。把此节点的颜色传递下去,然后此节点就能够初始化掉,表示此节点中不止有一张海报
{
if(sum[rt]!=-1){
sum[rt<<1]=sum[rt<<1|1]=sum[rt];
sum[rt]=-1;
}
} void update(int L,int R ,int c,int l,int r,int rt){
if(L<=l&&R>=r){
sum[rt]=c;
return ;
}
pushup(rt);
int m=(l+r)>>1;
if(L<=m) update(L,R,c,lson);
if(R>m) update(L,R,c,rson); } void query(int l,int r,int rt){
if(sum[rt]!=-1)//表示不仅仅有一张海报
{
if(!hash[sum[rt]]) cnt++;
hash[sum[rt]]=1;
return ;
}
if(l==r) return ;
int m=(l+r)>>1;
query(lson);
query(rson);
} int cheak(int aa,int nn,int num[])//推断这个点在那边
{
int l=0,r=nn-1;
while(l<=r){
int m=(l+r)>>1;
if(num[m]==aa) return m;
if(num[m]<aa) l=m+1;
else r=m;
}
return -1;
}
int main(){
int T,n;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
int m=0;
for(int i=0;i<n;i++){
scanf("%d%d",&a[i],&b[i]);
num[m++]=a[i];
num[m++]=b[i];
}
sort(num,num+m);
// for(int i=0;i<m;i++)
// printf("%d %d\n",i,num[i]);
int h=1;
for(int i=1;i<m;i++){
if(num[i]!=num[i-1])
num[h++]=num[i];
}
//puts("--------------");
// for(int i=0;i<h;i++)
// printf("%d %d\n",i,num[i]);
memset(sum,-1,sizeof(sum));
memset(hash,0,sizeof(hash));
for(int i=0;i<n;i++){
int l=cheak(a[i],h,num);
int r=cheak(b[i],h,num);
update(l,r,i,0,h,1);
}
cnt=0;
query(0,h,1);
printf("%d\n",cnt);
}
}

poj 2528 Mayor&#39;s posters的更多相关文章

  1. poj 2528 Mayor&#39;s posters 【线段树 + 离散化】

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

  2. POJ 2528 Mayor&#39;s posters 离散化+线段树

    题目大意:给出一些海报和贴在墙上的区间.问这些海报依照顺序贴完之后,最后能后看到多少种海报. 思路:区间的范围太大,然而最多仅仅会有10000张海报,所以要离散化. 之后用线段树随便搞搞就能过. 关键 ...

  3. 线段树区间更新,区间统计+离散化 POJ 2528 Mayor&#39;s posters

    题意:有一个非常长的板子(10000000长),在上面贴n(n<=10000)张海报.问最后从外面能看到几张不同的海报. 由于板子有10000000长,直接建树肯定会爆,所以须要离散化处理,对于 ...

  4. POJ 2528 Mayor&#39;s posters 离散化和线段树题解

    本题就是要往墙上贴海报,问最后有多少可见的海报. 事实上本题的难点并非线段树,而是离散化. 由于数据非常大,直接按原始数据计算那么就会爆内存和时间的. 故此须要把数据离散化. 比方有海报1 6   7 ...

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

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

  6. poj 2528 Mayor's posters 线段树+离散化技巧

    poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...

  7. POJ - 2528 Mayor's posters(dfs+分治)

    POJ - 2528 Mayor's posters 思路:分治思想. 代码: #include<iostream> #include<cstdio> #include< ...

  8. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  9. POJ 2528 Mayor's posters

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

随机推荐

  1. 48.自用qss

    /* R1 */ QDialog { background-image: url(:/images/background.png); } /* R2 */ QLabel { font: 9pt; co ...

  2. java三大版本解析

    JAVA三大版本代表着JAVA技术的三个应用领域:JAVASE.JAVAME.JAVAEE. JAVA以前很长一段时间被称为JAVA2,所以现在很多人习惯称为J2SE.J2ME.J2EE,它们表示的含 ...

  3. Web启动,停止Windows服务

    When you grow stronger,the world become more dangerous.当你变得越强大,这个世界反而会变得越危险. ServiceModel.cs代码: publ ...

  4. Codeforces Round #448

    Pizza Serparation #include<stdio.h> #include<string.h> #include<stdlib.h> #include ...

  5. Android RecyclerView、ListView实现单选列表的优雅之路.

    一 概述: 这篇文章需求来源还是比较简单的,但做的优雅仍有值得挖掘的地方. 需求来源:一个类似饿了么这种电商优惠券的选择界面: 其实就是 一个普通的列表,实现了单选功能, 效果如图:  (不要怪图渣了 ...

  6. 二分图的最大独立集 最大匹配解题 Hopcroft-Karp算法

    二分图模型中的最大独立集问题:在二分图G=(X,Y;E)中求取最小的顶点集V* ⊂ {X,Y},使得边 V*任意两点之间没有边相连. 公式: 最大独立集顶点个数 = 总的顶点数(|X|+|Y|)- 最 ...

  7. div 内容水平垂直居中

    对于前端布局来说.总有一些图片水平垂直居中老是不好看,影响整体美观,百度一大堆各种自适应方法,终于找到了一种比较简单,适用于所有场景的方法.. 1.对于布局来说.一个div搞定. <div id ...

  8. 统计之都 http://cos.name/

    http://cos.name/ IMS:一个洲际人际交流网络(为学生免费提供会员资格) 原文链接:http://cos.name/2014/07/ims-a-cross-continent-huma ...

  9. php生成唯一识别码uuid

    /*生成唯一标志*标准的UUID格式为:xxxxxxxx-xxxx-xxxx-xxxxxx-xxxxxxxxxx(8-4-4-4-12)*/ function uuid() { $chars = md ...

  10. (转)基于MVC4+EasyUI的Web开发框架形成之旅--框架总体界面介绍

    http://www.cnblogs.com/wuhuacong/p/3344096.html 在前面介绍了一些关于最新基于MVC4+EasyUI的Web开发框架文章,虽然Web开发框架的相关技术文章 ...