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

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

发现仅仅是简单地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. vmware笔试题目

    http://discuss.acmcoder.com/topic/58db8e2ebb0f44ba0e94e670 上面是完整的题目,下面一下我自己的想法. http://discuss.acmco ...

  2. CMD-echo

    echo 打印 <> echo ^< echo ^> echo 换行 echo 你好@echo.世界. echo 多行打印 > log.log 此时 > 无效.(我 ...

  3. lua math.random()

    math.random([n [,m]]) 用法:1.无参调用,产生[0, 1)之间的浮点随机数. 2.一个参数n,产生[1, n]之间的整数. 3.两个参数,产生[n, m]之间的整数. math. ...

  4. java8-3-LambdaMapReduce例子

    public class LambdaMapReduce { private static List<User> users = Arrays.asList( new User(1, &q ...

  5. Python 实现简单图片验证码登录

    朋友说公司要在测试环境做接口测试,登录时需要传入正确的图片的验证码,本着懒省事的原则,推荐他把测试环境的图片验证码写死,我们公司也是这么做的^_^.劝说无果/(ㄒoㄒ)/~~,只能通过 OCR 技术来 ...

  6. div 内容水平垂直居中

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

  7. 用Navicat自动备份mysql数据库

    以下文章转载自https://blog.csdn.net/u013628152/article/details/54909885,放在自己的博客园以供后面方便查询 —————————————————— ...

  8. 使用PCL::GPU::遇到问题

    一:使用GPU进行点云分割,理论上可以极大地加快分割速度: 于是对PCL1.7.1进行了编译,回到32位系统,重设QT,编译成功(时间好漫长,一定要配置仔细,否则编译一次又一次浪费更多时间): 使用时 ...

  9. 杭电 2088 Box of Bricks

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2088 解题思路:一堆高度不同的砖块,需要把它们砌成一堵墙,即每一堆砖的高度相同(即砖的总数除以砖的堆数 ...

  10. 杭电2060WA

    #include<stdio.h> int main() { int n,num,p,q,i,a[]={2,3,4,5,6,7}; scanf("%d",&n) ...