poj 2528 Mayor's posters(线段树)
题目: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(线段树)的更多相关文章
- POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...
- poj 2528 Mayor's posters 线段树+离散化技巧
poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) ...
- poj 2528 Mayor's posters 线段树区间更新
Mayor's posters Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Descript ...
- POJ 2528 Mayor's posters(线段树+离散化)
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [ ...
- poj 2528 Mayor's posters 线段树+离散化 || hihocode #1079 离散化
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the ...
- POJ 2528 Mayor's posters (线段树)
题目链接:http://poj.org/problem?id=2528 题目大意:有一个很上的面板, 往上面贴海报, 问最后最多有多少个海报没有被完全覆盖 解题思路:将贴海报倒着想, 对于每一张海报只 ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- POJ 2528 Mayor's posters (线段树+离散化)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions:75394 Accepted: 21747 ...
- POJ 2528 Mayor’s posters (线段树段替换 && 离散化)
题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 ...
随机推荐
- jquery-2.0.3.js和jquery-2.0.3.min.js的区别
两个文件的作用是完全一样的. jquery-2.0.3.js里的代码是没有进行处理的原代码,适合于人们阅读与研究. jquery-2.0.3.min.js里的代码进行过特殊的处理, 如变量的名称基本都 ...
- 2124: 等差子序列 - BZOJ
Description 给一个1到N的排列{Ai},询问是否存在1<=p1=3),使得Ap1,Ap2,Ap3,…ApLen是一个等差序列. Input 输入的第一行包含一个整数T,表示组数.下接 ...
- DiskGenius的 “终止位置参数溢出”错误解决方法。
(转帖)同事电脑系统启动突然明显变慢,重装系统后问题仍未解决(windowsxp sp3).帮忙分析感觉是磁盘分区表出现了错误,用通用PE工具箱进入PE系统,DiskGenius工具检查:“终止位置参 ...
- How to define Servlet filter order of execution using annotations
If we define Servlet filters in web.xml, then the order of execution of the filters will be the same ...
- poj 2387 Til the Cows Come Home (最短路,dijkstra模版题)
题目 #define _CRT_SECURE_NO_WARNINGS #include<string.h> #include<stdio.h> #include<math ...
- ZOJ 3261 Connections in Galaxy War(逆向并查集)
参考链接: http://www.cppblog.com/yuan1028/archive/2011/02/13/139990.html http://blog.csdn.net/roney_win/ ...
- MessageBox.Show()如何换行
MessageBox.Show("你好!\n\r可以使用", "换行");
- hdu 3441 Rotation
总的来说,这题要2次用到polya定理. 由题目条件A*A=B*B+1,变形为(A-1)*(A+1)=K*B*B; 分别分解A-1和A+1的质因数,在合并在一起. 第一步:搜索B,对B*B的正方形涂色 ...
- hdu2011
http://acm.hdu.edu.cn/showproblem.php?pid=2011 #include<iostream> #include<math.h> #incl ...
- cojs 简单的01串 题解报告
题意显然是求n位二进制串中不大于其逆序串,取反串,逆序取反串的所有串按字典序排序后的第k个 由于n很小,k很大所以我们可以考虑逐位确定 问题转化为了求方案数,这显然是可以用数位DP做的 设f[len] ...