poj2528 Mayor's posters 题意:在墙上贴海报,海报可以互相覆盖,问最后可以看见几张海报 思路:这题数据范围很大,直接搞超时+超内存,需要离散化: 离散化简单的来说就是只取我们需要的值来用,比如说区间[1000,2000],[1990,2012] 我们用不到[-∞,999][1001,1989][1991,1999][2001,2011][2013,+∞]这些值,所以我只需要1000,1990,2000,2012就够了,将其分别映射到0,1,2,3,在于复杂度就大大的降下来了…
[poj2528]Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 66154   Accepted: 19104 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their elect…
线段树需要的空间. 区间为1-->n 假设是一棵完全二叉树,且树高为i. 完全二叉树性质:第i层最多有2^(i-1)个结点. 那么 2^(i-1) = n;     i = log2(n)  + 1; 共有   2^i - 1 个结点, 即     2^(log2(n) + 1) - 1个结点 即2 * 2^log2(n)  - 1 =   2 * n - 1 但这是建立树是完全二叉树的情况下. 但是如图所示,树可能不是完全二叉树,最下面一层的结点个数>n,   我们以2n来来计算,那么就需要…
G - Mayor's posters POJ - 2528 这个题目要倒着来写,从后面往前面贴,因为前面的有些会被后面的覆盖. 所以我们就判断这张海报的位置有没有完全被覆盖,如果完全被覆盖了就不能贴,但是没有完全被覆盖就可以贴上去,然后更新掉这一段. #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #incl…
链接: http://poj.org/problem?id=2528 覆盖问题, 要从后往前找, 如果已经被覆盖就不能再覆盖了,否则就可以覆盖 递归呀递归什么时候我才能吃透你 代码: #include<stdio.h> #include<algorithm> #include<stdlib.h> #include<string.h> using namespace std; #define Lson r<<1 #define Rson r<…
POJ2528.Mayor's posters 这道题真的是线段数的经典的题目,因为数据很大,直接建树的话肯定不可以,所以需要将数据处理一下,没有接触离散化的时候感觉离散化这个东西相当高级,其实在不知道离散化是什么东西之前,就已经用过这种东西了,只是不知道叫什么.关于离散化,就是根据数的相对大小对他们进行映射,用小的数来表示他们.所以要先排序,然后去重,然后操作就可以.有排序版的离散化和STL版的离散化(自己起的名字 ...),代码里写的是排序版的,就是for循环遍历的时候,和身边的数比较一下是…
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 Problem Description In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecut…
Distance on the tree DSM(Data Structure Master) once learned about tree when he was preparing for NOIP(National Olympiad in Informatics in Provinces) in Senior High School. So when in Data Structure Class in College, he is always absent-minded about…
Mayor's posters Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 37346Accepted: 10864 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at…
题目链接:https://vjudge.net/problem/POJ-2528 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…
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…
解题报告 id=2528">地址传送门 题意: 一些海报,覆盖上去后还能看到几张. 思路: 第一道离散化的题. 离散化的意思就是区间压缩然后映射. 给你这么几个区间[1,300000],[3,5],[6,10],[4,9] 区间左右坐标排序完就是 1,3,4,5,6,9,10,300000; 1,2,3,4,5,6, 7 ,8; 我们能够把上面的区间映射成[1,8],[2,4],[5,7],[3,6]; 这样就节省了非常多空间. 给线段染色, lz标记颜色. #include <ma…
题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 : 很容易想到利用线段树来成段置换,最后统计总区间不同数的个数.但是这里有一个问题,就是区间可以很大,线段树开不了那么大的空间,遂想能不能离散化.实际上只记录坐标的相对大小进行离散化最后是不影响我们计算的,但是光是普通的离散化是不行的,就是我们贴海报的实际意义是对(l, r)段进行添加,而不是对于这个区间的点…
题意 : 在墙上贴海报, n(n<=10000)个人依次贴海报,给出每张海报所贴的范围li,ri(1<=li<=ri<=10000000).求出最后还能看见多少张海报. 分析 : 很容易想到利用线段树来成段置换,最后统计总区间不同数的个数.但是这里有一个问题,就是区间可以很大,线段树开不了那么大的空间,遂想能不能离散化.实际上只记录坐标的相对大小进行离散化最后是不影响我们计算的,但是光是普通的离散化是不行的,就是我们贴海报的实际意义是对(l, r)段进行添加,而不是对于这个区间的点…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 70365   Accepted: 20306 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 https://www.luogu.org/problem/UVA10587 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…
线段树 + 离散化 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…
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…
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…
题目传送门: POJ-2528 题意就是在一个高度固定的墙面上贴高度相同宽度不同的海报,问贴到最后还能看到几张?本质上是线段树区间更新问题,但是要注意的是题中所给数据范围庞大,直接搞肯定会搞出问题,所以要离散化,而离散化的过程中要注意一个问题,比方说1-10,1-5,6-10,本来是可以三张海报都可以看见的,但是按照题意来看是看不到的,因为他是一个点代表一个单位长度(诡异>_<),解决的办法则是对于距离大于1的两相邻点,中间再插入一个点...... 代码如下,我用了vector,和用数组的相差…
题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # include<vector> # include<list> # include<map> # include<set> # include<cstdlib> # include<string> # include<cstring&g…
Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 50888   Accepted: 14737 Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral post…
一条钩子由许多小钩子组成 更新一段小钩子 变成铜银金 价值分别变成1 2 3 输出最后的总价值 Sample Input11021 5 25 9 3 Sample OutputCase 1: The total value of the hook is 24. # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmat…
题目描述 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 placing…
HDU1698.Just a Hook 这个题是最最基础的成段更新的线段数的题目,直接贴代码吧. 代码: #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #include<cstdlib> #include<queue> #include<stack> #include<ma…
POJ3225.Help with Intervals 这个题就是对区间的各种操作,感觉这道题写的一点意思都没有,写到后面都不想写了,而且更神奇的是,自己的编译器连结果都输不出来,但是交上就过了,也是令人头大的操作,这题没意思,不要写了.我写到后面就写不下去了,直接去看了别人的代码... 代码: #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<…
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 placing the…
恩,这区间范围挺大的,需要离散化.如果TLE,还需要优化一下常数. AC代码 #include <stdio.h> #include <string.h> #include <map> #include <set> #include <algorithm> using namespace std; +; typedef pair<int, int> Pii; Pii a[ + ]; +], c[maxn]; ]; void build…
题意:给一个区间,表示这个区间贴了一张海报,后贴的会覆盖前面的,问最后能看到几张海报. 思路: 之前就不会离散化,先讲一下离散化:这里离散化的原理是:先把每个端点值都放到一个数组中并除重+排序,我们就得到了处理后的数组,现在我们只需要用二分查找端点值在整个数组的下标,这样就达到了离散化的目的,压缩了长度.因为这里很特殊,不能用一般的离散化去做,如果区间两端只差1,那么需要给这个区间再加一个值,这个其他题解讲到了. 这里的区间更新和上一题不太一样,有一些地方要注意一下 代码: #include<q…
题目大意:有t组数据,每组数据给你n张海报(1<=n<=10000),下面n组数据分别给出每张海报的左右范围(1 <= l <= r <= 10000000),下一张海报会覆盖前一张海报,求最后可见(包括完全和不完全可见)的海报有几张. 例如: 1 5 1 4 2 6 8 10 3 4 7 10 如上图所示,答案为4. 解题思路:其实这是一道区间染色问题,但是由于查找区间太大,显然直接建树会导致MLE,所以这里通过使用对区间的离散化来缩小查找范围.参考了一些大牛博客,简单说一…