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 立即下载

相关推荐

LeGO-LOAM运行kitti数据集

文章目录1. kitti-lego-loam2. 改动3. 实验结果4. evo轨迹测评 1. kitti-lego-loam 链接:kitti-lego-loam kitti-lego-loam提供了将kitti序列转化成rosbag的代码,在kittibag中. 需要注意下数据文件的存放顺序,以00序列为例: datafolder          |____results          &

Zlp19970106的博客 8704

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

AFSim仿真系统—几何视角下的子系统交互机制解析

本文深入解析了AFSim仿真系统中子系统交互的几何机制。通过剖析世界坐标系、实体坐标系、部件坐标系等七层空间定位体系,阐述了传感器探测、目标指示等交互行为背后的几何原理与限制条件。掌握这套几何视角,是构建高保真、符合物理现实的AFSim仿真模型的关键,能有效避免坐标混乱、交互失效等常见问题。

terraform7cloud的博客 492

POJ2528-Mayor's posters

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

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

从UC3842的FB脚到COMP脚:一次讲透反激电源两种光耦反馈接法的选择与实战

本文深入探讨了UC3842 PWM控制器在反激式开关电源设计中的两种光耦反馈接法:FB脚与COMP脚方案。通过分析信号极性差异、稳定性特点及动态响应性能,提供场景化选型指南和可靠性设计要点,帮助工程师优化反馈环路设计,提升系统稳定性与效率。特别针对TL431和PC817等关键元件在温度漂移、老化衰减等实际问题给出解决方案。

weixin_28717683的博客 705

【rPPG】基于多光谱摄像头的非接触式睡眠血氧监测系统(传统建模方法解析)

本文深入解析了基于多光谱摄像头的非接触式睡眠血氧监测系统,重点探讨了rPPG技术的原理、硬件设计及传统建模方法。通过多光谱摄像头捕捉皮肤微弱光学变化,实现医疗级精度的心率和血氧监测,特别适合长期睡眠监测场景。文章详细介绍了摄像头选型、照明系统设计以及PBV模型等核心技术,并对比了与传统传感器的性能差异。

weixin_30300225的博客 562

poj2528(线段树+离散化)

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

weixin_34279184的博客 252

欧姆龙OMRON PLC之HostLink通讯协议(四)-FINS命令进阶应用与调试技巧

本文深入探讨欧姆龙OMRON PLC的HostLink通讯协议中FINS命令的进阶应用与调试技巧。文章聚焦实战排错,详细解析命令帧解剖、响应帧解读与网络抓包三大核心方法,并分享性能优化策略,如合并读写与异步设计。同时介绍了强制操作、多存储区访问等高级命令的应用场景,旨在帮助工程师高效解决现场通讯问题,提升系统稳定性与效率。

nept的博客 750

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

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

月巴虫丰博客 1611

智慧城市中的CV:交通流量监控与行人检测

智慧城市中的CV:交通流量监控与行人检测 ,人工智能,计算机视觉,大模型,AI,计算机视觉作为人工智能的重要分支,通过分析和理解图像或视频数据,为智慧城市提供了强大的感知能力。在交通管理领域,计算机视觉技术可实现交通流量监控、行人检测、违章行为识别等功能,助力构建高效、安全、绿色的城市交通系统。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 5万+

Arduino 系列:Arduino Due 系列 (基于 ATSAM3X8E)_(5).电源管理与电压调节

电源管理与电压调节是确保嵌入式系统稳定性和可靠性的关键环节。通过合理选择电源输入方式、使用高效的电压调节器、设计适当的滤波电路和实施动态电源管理,可以有效提高系统的性能和寿命。同时,使用电源调试工具和编写调试代码,可以帮助开发者及时发现和解决问题。希望本文档能为使用 Arduino Due 的开发者提供有用的信息和指导。

2401_87715305的博客 1309

poj 2528 Mayor‘s posters

线段树

weixin_46266058的博客 731

ATE FT ChangeKit学习总结-20250630

半导体封装测试中的ChangeKit是Handler测试机的关键配套治具,主要用于适配不同芯片封装尺寸的FT测试。其主要特点包括:1)适应性,可快速切换不同测试设置;2)精准性,确保器件测试安全;3)高效性,减少停机时间。主要组件含Shuttle传送机构、HotPlate预热盘、DockPlate连接件和Contactor压头。设计需考虑Handler型号、芯片规格及PCB匹配(如140mm标准孔位),特别在低温测试时需注意吹气块布局。ChangeKit实现了测试设备的灵活配置,提升了半导体测试效率。

歌颂苦难的行为是无耻的; 1752

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

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

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

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、付费专栏及课程。

余额充值