题目: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. LintCode-Implement Iterator of Binary Search Tree

    Design an iterator over a binary search tree with the following properties: Elements are visited in ...

  2. DOM文档对象总结

    DOM总结: DOM:文档对象模型document object model DOM三层模型: DOM1:将HTML文档封装成对象 DOM2:将XML文档封装成对象 DOM3:将XML文档封装成对象 ...

  3. Ffmpeg 定位文件(seek file)

    有朋友问到ffmpeg播放文件如何定位问题,我想到应该还有一些新手朋友对这一块比较陌生.ffmpeg定位问题用到seek方法,代码 如下: void SeekFrame(AVFormatContext ...

  4. 在MAC上安装虚拟机搭建Ubuntu开发环境

    由于工作需要,需要在LINUX环境搭建服务器,但是工作中使用的是MAC系统,只好用虚拟机来搭建LINUX服务器环境.下面记录介绍一下搭建步骤以供需要的人参考使用. 下载准备 虚拟机使用VMWare   ...

  5. Codeforces Gym 100342J Problem J. Triatrip 三元环

    题目链接: http://codeforces.com/gym/100342 题意: 求三元环的个数 题解: 用bitset分别统计每个点的出度的边和入度的边. 枚举每一条边(a,b),计算以b为出度 ...

  6. SQLServer调试

    1.普通调试 直接点击SSMS客户端上的调试按钮即可 2.存储过程调试 2.1 定义存储过程(以Northwind数据库为例) USE [Northwind] GO /****** Object: S ...

  7. C# 数据结构--排序[下]

    希尔排序(Shell Sort) 排序思想: 先取一个小于n的整数d1作为第一个增量,把文件的全部记录分组.所有距离为d1的倍数的记录放在同一个组中.先在各组内进行直接插入排序:然后,取第二个增量d2 ...

  8. centos6.5\win7双系统安装配置

    一.安装所需软件 1.分区助手专业版PACNPro.exe(必需):用来对硬盘分区,将磁盘的一部分格式化成Linux可以识别的ext3格式 2.Ext2Fsd(硬盘安装必需,光盘安装不用):因为Win ...

  9. linux源码阅读笔记 asm函数

    在linux源码中经常遇到__asm__函数.它其实是函数asm的宏定义 #define __asm__ asm,asm函数让系统执行汇编语句. __asm__常常与__volatile__一起出现. ...

  10. git安装及使用

    一.安装 1.从http://code.google.com/p/msysgit/下载Git-1.8.4-preview20130916.exe,并安装. 2.新建git目录,右键选择Git Bash ...