题目:http://poj.org/problem?id=2528

题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度。现在往墙上贴N张海报,每张海报的宽度是任意的,

但是必定是单位宽度的整数倍,且<=1QW。后贴的海报若与先贴的海报有交集,后贴的海报必定会全部或局部覆盖

先贴的海报。现在给出每张海报所贴的位置(左端位置和右端位置),问张贴完N张海报后,还能看见多少张海报?

(离散化)+ 线段树

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = +;
int n, cnt;
int map[*maxn][], ans, f[*maxn];
struct node
{
int l, r, n; //n代表是哪种颜色
} a[*maxn];
struct node2
{
int point, num; //原来点的编号, 新编的号
} s[*maxn];
void init(int l, int r, int i) //建树
{
a[i].l = l;
a[i].r = r;
a[i].n = ;
if(l != r)
{
int mid = (l+r)/;
init(l, mid, *i);
init(mid+, r, *i+);
}
}
void insert(int i, int l, int r, int m)//从第i个点,查找区间【l,r】,并把颜色标记为m
{
if(a[i].l == l && a[i].r == r)
{
a[i].n = m;
return;
}
int mid = (a[i].l+a[i].r)/;
if(a[i].n>) //颜色已有,对其子树赋值
{
a[*i].n = a[i].n;
a[*i+].n = a[i].n;
a[i].n = ;
}
if(l >= a[*i+].l)
insert(*i+, l, r, m);
else if(r <= a[*i].r)
insert(*i, l, r, m);
else
{
insert(*i, l, mid, m);
insert(*i+, mid+, r, m);
}
}
void solve(int i)
{
if(a[i].n)
{
if(!f[a[i].n])
{
ans++;
f[a[i].n] = ;
}
return;
}
solve(*i);
solve(*i+);
}
int cmp(node2 x, node2 y)
{
return x.point<y.point;
} int main()
{
int t, i, tmp, cnt;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(i = ; i < n; i++)
{
scanf("%d%d", &map[i][], &map[i][]);
s[i*].point = map[i][];
s[i*+].point = map[i][];
s[*i].num = -(i+);
s[*i+].num = i+;
}
sort(s, s+*n, cmp);
tmp = s[].point;
cnt = ;
for(i = ; i < *n; i++)
{
if(tmp != s[i].point)
{
cnt++;
tmp = s[i].point;
}
if(s[i].num < )
map[-s[i].num-][] = cnt;
else
map[s[i].num-][] = cnt;
}
init(, cnt, );
for(i = ; i < n; i++)
insert(, map[i][], map[i][], i+);
memset(f, , sizeof(f));
ans = ;
solve();
printf("%d\n",ans);
}
return ;
}

poj 2528 Mayor's posters(线段树)的更多相关文章

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

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

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

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

  3. poj 2528 Mayor's posters 线段树区间更新

    Mayor's posters Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...

  4. POJ 2528 Mayor's posters(线段树+离散化)

    Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...

  5. poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化

    Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...

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

    题目链接:http://poj.org/problem?id=2528 题目大意:有一个很上的面板, 往上面贴海报, 问最后最多有多少个海报没有被完全覆盖 解题思路:将贴海报倒着想, 对于每一张海报只 ...

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

    题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...

  8. POJ 2528 Mayor's posters (线段树+离散化)

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

  9. POJ 2528 Mayor’s posters (线段树段替换 && 离散化)

    题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 ...

随机推荐

  1. DB天气app冲刺二阶段第十天

    昨天困到不行了 所以就写了那么几句..所以今天好好写写了要.. 今天的收获了一个很重要的问题 就还是api接口的事情,以前的那个接口虽然能用但是总是不稳定,今天由决定百度的一下然后就发现了一个很好用的 ...

  2. Careercup - Facebook面试题 - 23594662

    2014-05-02 03:19 题目链接 原题: Given a sequence of numbers A() ..A(n), find the continuous subsequenceA(i ...

  3. Google history

    传说,硅谷的公司在和微软的竞争中一直处于下风,不论在市场,人才,还是在打官司上,直到婴儿巨人Baby Giant谷歌的出现,历史才出现前所未有的改变.Google以一个强大的挑战者的身份出现在人们的视 ...

  4. 3157: 国王奇遇记 & 3516: 国王奇遇记加强版 - BZOJ

    果然我数学不行啊,题解君: http://www.cnblogs.com/zhuohan123/p/3726933.html const h=; var fac,facinv,powm,s:..]of ...

  5. 2012 Asia JinHua Regional Contest

    Draw Something http://acm.hdu.edu.cn/showproblem.php?pid=4450 o(n)统计输入每个数的平方和. #include<cstdio> ...

  6. [转载]C# ListView用法详解

    一.ListView类 1.常用的基本属性: (1)FullRowSelect:设置是否行选择模式.(默认为false) 提示:只有在Details视图该属性才有意义. (2) GridLines:设 ...

  7. Gitlab安装和使用相关信息

    Gitlab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目.它拥有与Github类似的功能,能够浏览源代码,管理 ...

  8. ubuntu12.10+NDK r9 编译 ffmpeg 的一些参考资料Perhaps you should add the directory containing `libssl.pc'

    首先入门级的 编译宝典: https://trac.ffmpeg.org/wiki/CompilationGuide/Android http://www.roman10.net/how-to-bui ...

  9. [2-sat]HDOJ1824 Let's go home

    中问题 题意略 和HDOJ 3062一样 这里 每个队员都有 选 和 不选 两种, 即 上篇所说的$x$和$x’$ 建图:队长(a)留下或者其余两名队员(b.c)同时留下 那么就是$a' \Right ...

  10. eclipse导入maven web 项目 但是不显示成web 项目

    http://blog.csdn.net/jun55xiu/article/details/9028403 1:导入Maven webapp项目(以extdirectspring-demo为例): i ...