poj 2528 Mayor's posters 题目链接: http://poj.org/problem?id=2528 思路: 线段树+离散化技巧(这里的离散化需要注意一下啊,题目数据弱看不出来) 假设给出: 1~10 1~4 7-10 最后可以看见三张海报 如果离散化的时候不注意,就会变成 1 4 7 10(原始) 1 2 3 4 (离散化) 转化为: 1~4 1~2 3~4 这样的话最后只能看见两张海报 解决办法,如果原数据去重排序后相互之间差值大于1,则在他们之间再插入一个数值,使得大…
Mayor's posters 转载自:http://blog.csdn.net/winddreams/article/details/38443761 [题目链接]Mayor's posters [题目类型]线段树+离散化 &题意: 给出一面墙,给出n张海报贴在墙上,每张海报都覆盖一个范围,问最后可以看到多少张海报 &题解: 海报覆盖的范围很大,直接使用数组存不下,但是只有最多10000张海报,也就是说最多出现20000个点,所以可以使用离散化,将每个点离散后,重新对给出控制的区间,这样…
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an ele…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:75394   Accepted: 21747 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral poste…
POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报左右坐标范围不超过10000000. 一看见10000000肯定就要离散化了,因为建树肯定是建不下.离散化的方法是:先存到一个数组里面,然后sort,之后unique去重,最后查他离散化的坐标lower_bound就行了.特别注意如果是从下标为0开始存储,最后结果要加一.多亏wmr神犇提醒. 这题是…
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值.由于l和r范围比较大,内存就不够了,所以就用离散化的技巧 比如将1 4化为1 2,范围缩小,但是不影响答案. 写了这题之后对区间更新的理解有点加深了,重点在覆盖的理解(更新左右两个孩子节点,然后值清空),还是要多做做题目. #include <iostream> #include <cst…
题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 : 很容易想到利用线段树来成段置换,最后统计总区间不同数的个数.但是这里有一个问题,就是区间可以很大,线段树开不了那么大的空间,遂想能不能离散化.实际上只记录坐标的相对大小进行离散化最后是不影响我们计算的,但是光是普通的离散化是不行的,就是我们贴海报的实际意义是对(l, r)段进行添加,而不是对于这个区间的点…
Mayor's posters Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=2528 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at al…
题目:http://poj.org/problem?id=2528 题意:有一面墙,被等分为1QW份,一份的宽度为一个单位宽度.现在往墙上贴N张海报,每张海报的宽度是任意的, 但是必定是单位宽度的整数倍,且<=1QW.后贴的海报若与先贴的海报有交集,后贴的海报必定会全部或局部覆盖 先贴的海报.现在给出每张海报所贴的位置(左端位置和右端位置),问张贴完N张海报后,还能看见多少张海报? (离散化)+ 线段树 #include <iostream> #include <cstdio>…
题目链接:http://poj.org/problem?id=2528 题目大意:有一个很上的面板, 往上面贴海报, 问最后最多有多少个海报没有被完全覆盖 解题思路:将贴海报倒着想, 对于每一张海报只需要判断他要贴的位置是否已经全部被之前的海报覆盖就可以了, 如果没有被覆盖那么这个海报最后是没有被完全覆盖的, 如果被覆盖了, 那么最后是被完全覆盖的.标准的线段树题目. 代码如下: #include<stdio.h> #include<vector> #include<map&…
题目链接 题意 用不同颜色的线段覆盖数轴,问最终数轴上有多少种颜色? 注:只有最上面的线段能够被看到:即,如果有一条线段被其他的线段给完全覆盖住,则这个颜色是看不到的. 法一:线段树 按题意按顺序模拟即可. 法二:线段树+离线 将整个过程倒过来看待,如果要加进去的线段所在的区域已经完全被覆盖,那么这条线段就没有贡献,否则就有\(1\)的贡献. 法三:并查集+离线 离线处理思想同上. 用\(fa[\ ]\)数组记录某个元素左边距其最近的没有被覆盖的点的坐标.那么对于当前覆盖的线段\([l,r]\)…
给一块最大为10^8单位宽的墙面,贴poster,每个poster都会给出数据 a,b,表示该poster将从第a单位占据到b单位,新贴的poster会覆盖旧的,最多有10^4张poster,求最后贴完,会看到几张poster (哪怕只露出一个单位,也算该poster可见): 我一看这么大数据,又看了下时间限制只有1s,不科学啊,如果真的按10^8建树不可能过时间啊,而且根据它的空间限制,大概只能建10^7这么大的数组. 后来搜博客发现大家的标题都写着离散化,原来用离散化做这个题目,但是我不会离…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45703   Accepted: 13239 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post…
做这题建议看一下该题的discuss. #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <set> /* 题意:给出n张海报的左端点和右端点,按顺序往墙上贴.问最后整张墙能看到几张海报. 注意:按题意是如此够造树的,即每个点其实是一小块段. |___|___|___|___|___|___|___|___| 1 2 3…
题意: 一共有n张海报, 按次序贴在墙上, 后贴的海报可以覆盖先贴的海报, 问一共有多少种海报出现过. 题解: 因为长度最大可以达到1e7, 但是最多只有2e4的区间个数,并且最后只是统计能看见的不同海报的数目,所以可以先对区间进行离散化再进行区间覆盖的操作. 由于墙上不贴东西的时候对后面没有影响, 所以可以不建树, 直接memset一下就好了. 因为是区域覆盖的问题, 树上原来的点并不会对后面的结果产生影响, 所以可以只修改lazy标记而不对树进行修改. 最后再用建树的操作访问一下lazy标记…
任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 77814   Accepted: 22404 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign hav…
Mayor's posters Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an ele…
线段树 + 离散化 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral…
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 51175 Accepted: 14820 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters…
/* poj 2528 Mayor's posters 线段树 + 离散化 离散化的理解: 给你一系列的正整数, 例如 1, 4 , 100, 1000000000, 如果利用线段树求解的话,很明显 会导致内存的耗尽.所以我们做一个映射关系,将范围很大的数据映射到范围很小的数据上 1---->1 4----->2 100----->3 1000000000----->4 这样就会减少内存一些不必要的消耗 建立好映射关系了,接着就是利用线段树求解 */ #include<ios…
POJ - 2528 Mayor's posters 思路:分治思想. 代码: #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define ll long long #define ls rt<<1,l,m #define rs rt<<1|1,m+1,r #define pb push_back const int INF=0x3f3f3f…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 43507   Accepted: 12693 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post…
题目链接:http://poj.org/problem?id=2528 Time Limit: 1000MS Memory Limit: 65536K Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at thei…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 59239   Accepted: 17157 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post…
题目链接: 传送门 Mayor's posters Time Limit: 1000MS     Memory Limit: 65536K Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim…
题目传送门 题意:在一面墙上贴海报,有先后顺序,问最后有多少张不同的海报(指的是没被覆盖或者只是部分覆盖的海报) 分析:这题数据范围很大,直接搞超时+超内存,需要离散化:离散化简单的来说就是只取我们需要的值来用,比如说区间[1000,2000],[1990,2012] 我们用不到[-∞,999][1001,1989][1991,1999][2001,2011][2013,+∞]这些值,所以我只需要1000,1990,2000,2012就够了,将其分别映射到0,1,2,3,在于复杂度就大大的降下来…
Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2528 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been plac…
Time limit 1000 ms Memory limit 65536 kB Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finall…
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for…
注意离散化!!!线段树的叶子结点代表的是一段!!! 给出下面两个简单的例子应该能体现普通离散化的缺陷: 1-10 1-4 5-10 1-10 1-4 6-10 普通离散化算出来的结果都会是2,但是第二组样例结果是3 如果相邻数字间距大于1的话,在其中加上任意一个数字,比如加成[1,2,3,6,7,10],然后再做线段树就好了. 线段树功能:update 成段更新,query 查询整个线段树 #include <iostream> #include <cstdio> #include…