Poj 2528 Mayor's posters

POJ2528-Mayor's posters 测试数据 POJ2528-Mayor's posters 测试数据。数据来源:Alberta Collegiate Programming Contest 2003.10.18 – 问题G 立即下载

Mayor's posters
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 40570 Accepted: 11798

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 placing the posters and introduce the following rules:
  • Every candidate can place exactly one poster on the wall.
  • All posters are of the same height equal to the height of the wall; the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown).
  • The wall is divided into segments and the width of each segment is one byte.
  • Each poster must completely cover a contiguous number of wall segments.

They have built a wall 10000000 bytes long (such that there is enough place for all candidates). When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width. Moreover, the candidates started placing their posters on wall segments already occupied by other posters. Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections.
Your task is to find the number of visible posters when all the posters are placed given the information about posters' size, their place and order of placement on the electoral wall.

Input

The first line of input contains a number c giving the number of cases that follow. The first line of data for a single case contains number 1 <= n <= 10000. The subsequent n lines describe the posters in the order in which they were placed. The i-th line among the n lines contains two integer numbers li and ri which are the number of the wall segment occupied by the left end and the right end of the i-th poster, respectively. We know that for each 1 <= i <= n, 1 <= li <= ri <= 10000000. After the i-th poster is placed, it entirely covers all wall segments numbered li, li+1 ,... , ri.

Output

For each input data set print the number of visible posters after all the posters are placed.

The picture below illustrates the case of the sample input.

Sample Input

1
5
1 4
2 6
8 10
3 4
7 10

Sample Output

4

题意:给n张海报能贴瓷砖的范围,问,最终可以看见多少张海报

心得:线段树的离散化的第一步,以后写线段树绝对要多建几个函数,好修改,看代码↓


#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm> 
#define Max 10005
using namespace std;
struct node{
	int l, r, m, s;
}Tree[Max<<3];
int li[Max], ri[Max];
int point[Max<<2];
int see[Max];
int ans;
int n, m, ni;

void Complex(){
	memset(li,0,sizeof(li));
	memset(ri,0,sizeof(ri));
	memset(point,0,sizeof(point));
	memset(see,0,sizeof(see));
}

void Build(int l,int r,int k)
{
	Tree[k].l = l;
	Tree[k].r = r;
	Tree[k].s = -1;
	Tree[k].m = (l+r)>>1;
	if(l==r)	return;
	Build(Tree[k].m+1,r,k+k+1);
	Build(l,Tree[k].m,k+k);
	return;
}

void update(int l, int r, int k)
{
	if(Tree[k].l == l && Tree[k].r == r)
	{
		Tree[k].s = ni;	
		return;
	}		
	else if(Tree[k].s != -1)
	{
		Tree[k+k].s = Tree[k+k+1].s = Tree[k].s;
		Tree[k].s = -1;
	}	
	
	if(r <= Tree[k].m)	update(l, r, k+k);
	else if(l > Tree[k].m)	update(l, r, k+k+1);
	else
	{
		update(l, Tree[k].m, k+k);
		update(Tree[k].m + 1, r, k+k+1);
	}
	return;
}

void Query(int k)		//统计 
{
	if(Tree[k].s>=0)
	{
		if(!see[Tree[k].s]++)		ans++;
		return;
	}
	Query(k+k);
	Query(k+k+1);
	return;
}

int Bin(int xi)			//二分查找特定点在关键点数字中的位置,为了更新线段树 
{
	int l = 1, r = m;
	while(l<=r)
	{
		int mi = (l+r)>>1;
		if(xi == point[mi])		return mi;
		if(xi >= point[mi])		l = mi + 1;
		else	r = mi - 1;
	}
	return -1;
}

void Myscanf()			//统一输入,方便修改 
{
	ans = 0;
	m = 1;
	scanf("%d",&n);
	for(int i=0; i<n; i++)
	{
		scanf("%d%d",&li[i],&ri[i]);
		point[m++] = li[i];
		point[m++] = ri[i];
	}
}

void Point_Do()				//先排序在去重,达到离散的效果 
{
	int mi = 0;
	sort(point+1,point+1+m);
	for(int i=1; i<=m; i++)
	{
		if(point[i]!=point[mi])		point[++mi] = point[i]; 		//去重
	}		
	m = mi;
}

void Find_Point()
{
	for(int i=0; i<n; i++)
	{
		ni = i;
		update(Bin(li[i]),Bin(ri[i]),1);
	}
}

int main()
{
	int num;
	scanf("%d",&num);
	while(num--)
	{
		Complex();			//初始化函数 
		Myscanf();			//输入函数 
		Point_Do();			//处理关键点函数 
		Build(1,m,1);		//建树函数 
		Find_Point();		//对各个海报范围的处理函数 
		Query(1);			//统计函数 
		printf("%d\n",ans);			//输出结果 
	}	

	return 0;
}


POJ2528-Mayor's posters【区间映射压缩(离散化)+线段树】 POJ2528-Mayor's posters 【区间映射压缩(离散化)+线段树】 解题报告+AC代码 http://hi.youkuaiyun.com/!s/83XZJU ========> 我的所有POJ解题报告链接: http://blog.youkuaiyun.com/lyy289065406/article/details/6642573 立即下载

相关推荐

mt7601 kernel 4.19内核集成版本,以及源码编译相关问题

/os/linux/Makefile.6文件: 添加 EXTRA_CFLAGS += -Wno-incompatible-pointer-types -Wno-date-time。看下iwpriv与iwconfig的源码区别,左侧为iwconfig ,没有用到ioctl,右侧为iwpriv。1、init_timer kernel 4.19内核版本API已经改变,使用timer_setup。使用iwpriv 提示如下,iwpriv工具无法使用了,而iwconfig可以使用。makefile的修改。

1591

POJ - 2528(线段树+离散化)详解

//#if 0 #include <map> #include <stack> #include <queue> #include <vector> #include <math.h> #include <string> #include <stdio.h> #include <string.h> #i...

仰望蓝天的博客 650

Unity 常见问题 之 打包编译的报错 Unable to sign the application; please provide passwords!

Unity 常见问题 之 打包编译的报错 Unable to sign the application; please provide passwords! 目录 Unity 常见问题 之 打包编译的报错 Unable to sign the application; please provide passwords! 一、简单介绍 二、问题描述 三、原因分析 四、可能的解决方法 方法一:取消 Keystore 设置即可 方法二:重新添加 Keystore 相关设置 一...

仙魁XAN 1万+

POJ2528-Mayor's posters

全解题报告索引目录 -> 【北大ACM – POJ试题分类】 转载请注明出处:http://exp-blog.com ------------------------------------------------------------------------- 大致题意: 有一面墙,被等分为1QW份,一份的宽度为一个单位宽度。现在往墙上贴N张海报,每张海报的宽度是任意...

ζёСяêτ - 小優YoU 1万+

从论文到生产:iSLIP优先级匹配算法在SDN交换机中的20年演进史

本文回顾了iSLIP优先级匹配算法在SDN交换机中的20年演进历程,从斯坦福大学的原始论文到现代芯片实现。通过独特的指针滑动和迭代循环机制,iSLIP算法显著提升了交换机的吞吐量和公平性,解决了传统FIFO调度的队头阻塞问题。文章详细探讨了算法在硬件实现中的工程挑战、开源实践及未来AI时代的智能调度方向。

weixin_29230649的博客 331

KUKA .RSI 软件包

KUKA RSI软件包通过XML文件使得机器人与外部设备(传感器通讯)通讯成为了可能,但仍存在诸多限制,该模块最多允许9台设备进行连接,有限的IO口,匮乏的功能,并且需要投入大量精力琢磨相关说明文档。为此开发人员针对KUKA实时通讯,做了一些开源的接口使得上位机与机械臂的通讯更为简单。

huhu7777的博客 3293

poj2528(线段树+离散化)

题目链接:https://vjudge.net/problem/POJ-2528 题意:在区间[1,1e7]内染色,依次染n(<=1e4)中颜色,给出每种颜色染色的范围,可重叠,求最终有多少种颜色。 思路:继续肝线段树。。被这题虐了一下午加一晚上QAQ。    首先要想到离散化,因为区间为1e7,直接做的话时间空间都做不到。但因为是区间,这里不能简单的离散化,比如1、5离散化为1、2是...

weixin_34279184的博客 252

Tessent ICL语法详解:如何高效定义SIB、TDR和TAP模块

本文深入解析Tessent ICL语法,指导如何高效定义SIB、TDR和TAP模块以构建芯片测试网络。通过实战代码示例,详细阐述了各模块的端口声明、接口角色与核心寄存器定义,并提供了顶层集成连接方法与调试技巧,帮助DFT工程师精准描述测试仪器拓扑,提升Tessent工具链使用效率。

silver的专栏 492

线段树之离散化(POJ-2528)

线段树系列之离散化,介绍了离散化的步骤以及线段树离散化的应用。

月巴虫丰博客 1611

大模型产品Deepseek(七)、可视化本地知识库搭建详细教程(Cherry Studio)

Cherry Studio 为智能体的开发提供了一个强大的可视化平台,结合大模型和嵌入式知识库,它可以在多个应用场景中提供智能化的支持。如果你有进一步的需求或问题,可以继续在 Cherry Studio 中进行更多自定义配置,或者通过 API 调用集成到你的应用中。现在,知识库已经搭建并与 DeepSeek 模型连接好,接下来,我们将使用 Cherry Studio 提供的可视化界面进行智能提问。为了让智能体能够通过大模型查询到知识库中的信息,你需要为知识库配置索引和匹配模型。

xiaoqi270620903的专栏 1333

北斗导航 | 2023 PTTI会议论文 2023 ITM会议论文 2022 ION GNSS+ 会议论文下载:ION 美国导航学会

2023 国际技术会议(ITM) 2023 精密时间和时间间隔系统和应用会议(PTTI) 2022 美国导航学会国际会议(ION GNSS +)

尘世冰封的专栏 4613

poj 2528 Mayor‘s posters

线段树

weixin_46266058的博客 731

三相五柱式消弧线圈自动测控装置设计与实现

本文设计了一种基于STM32的三相五柱式消弧线圈自动测控装置。该装置采用信号注入法检测系统对地电容电流,通过PID自适应算法调节消弧线圈电感值,实现单相接地故障时的快速补偿。硬件系统包含信号采集、注入、控制执行等模块,软件采用Goertzel算法提取特征频率信号,结合增量式PID实现精确控制。实验结果表明,装置电容检测误差小于2%,调谐响应时间小于50ms,满足配电网对消弧线圈自动调谐的技术要求。

AI的内部世界的博客 239

poj 2528 Mayor's posters

线段树+离散化处理。 写的我好蛋疼啊!!! 不过总算过了。 /* POJ: 2528 Mayor's posters */ #include #include #include #include #include #include #include #include #include #include #include using namespace std; c

stormdpzh的专栏 460

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

poj2528Mayor's posters(线段树)

最近此题根本没有什么卡点,从昨天晚上开始

u010839163的专栏 569

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Mayor's posters poj 2528

题目链接:http://poj.org/problem?id=2528 题目大意:贴海报,可以互相覆盖,问贴完所有海报最后能看到几张海报。 先离散化然后用线段树求解即可。 代码: #include #include #include using namespace

凌风 1384

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

POJ 2528 Mayor's posters

POJ 2528 Mayor’s posters题目链接Description给N个海报,每个海报有L,R,表示这块区域被覆盖,问最后有多少块区域被覆盖Algorithm线段树每个节点的附加信息v的意义是 这块区域没有任何一个海报覆盖 v = 0 这块区域内(不完全重合)有不止一块海报覆盖 v = 0 这块区域只有一块海报覆盖 v = i (i 为第 i 个海报) 线段树三个函数 build 建树,

more time 210

POJ2528——Mayor's posters

题目链接:Mayor’s posters 推荐博客:【完全版】线段树(转载) 题目: 在墙上贴海报,海报可以互相覆盖,问最后可以看见几张海报(后面贴的海报覆盖前面的) 分析: 离散化要保存所有需要用到的值,排序后,分别映射到1~n,这样复杂度就会小很多很多 而这题的难点在于每个数字其实表示的是一个单位长度(并且一个点),这样普通的离散化会造成许多错误 代码: #include<stdio.h...

浦柳人的博客 372

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

POJ.2528 Mayor’s posters (线段树 区间更新 区间查询 离散化)题意分析贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报。最多有10000张海报,海报左右坐标范围不超过10000000。 一看见10000000肯定就要离散化了,因为建树肯定是建不下。离散化的方法是:先存到一个数组里面,然后sort,之后unique去重,最后查他离散化的坐标lower_bo

Pengwill's Blog 332

poj2528-Mayor's posters的树堆解法

二叉搜索树的有序性质使得查找操作时间时长为O(log N),而不需要遍历整个数组。但是如果二叉搜索树退化为单链程序效率会快速下降,因此出现了一些方法使得二叉搜索树趋向平衡,treap也是其中较为简单的一种。         树堆在普通二叉搜索树的每个节点上新增了一个随机数,每次在二叉搜索树插入一个节点后,进行左旋或者右旋使之满足堆序性质,值得注意的是,这个随机数仅仅是为了是树趋向平衡,本身可

陈杰的专栏 549

POJ2528 Mayor's posters

POJ上这道题的数据据说很弱,导致很多实际上错误的代码都

那些年我们切过的题 871

POJ - 2528 Mayor's posters(区间覆盖,离散化)

POJ - 2528 Mayor’s posters 题目 给出 n 段区间,区间按给出的顺序会覆盖掉前面的区间,问最后能看到多少不同的区间。 分析 这题只需要用到懒惰标记即可,线段树没有维护什么东西,有懒惰标记 c 代表这个区间被 c 覆盖了。 只不过要用到离散化,题目给出的数据我们只在乎他们的相对大小,相对大小才会影响到区间覆盖的结果 。 通常离散化的时侯是离散到连续的区间,但是有问题,比如数...

Stormjing的博客 311

POJ-2528-Mayor's posters

POJ-2528-Mayor’s posters 传送门 这道题线段树。离散化。二分。 题目大意:一块宣传栏,贴不同颜色的海报,宽度与宣传栏等宽,长度不等,给出长度区间表示,用后者覆盖前者,问最后能见几种颜色的海报 这道题规模1e7。普通的二叉树肯定会超空间。。 思路如下: 离散化: 提取海报的端点,sort去重。把原来的端点映射到新的线段上即可。压缩完成。 然后端点修改。这里二分查找原顺序所在的...

qq_44624316的博客 158
上一篇: Poj 2349 Arctic Network
下一篇: Poj 1255 覆盖的面积
梁千仞
博客等级 码龄15年 12粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值