The Skyline Problem

本文探讨了如何通过编程实现城市天际线的可视化,详细解释了每个建筑的几何信息如何转换为独特的天际线轮廓。通过提供一个算法实例,包括建筑物的位置、高度和宽度,本文展示了如何输出由所有建筑物共同形成的天际线轮廓。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as shown on a cityscape photo (Figure A), write a program to output the skyline formed by these buildings collectively (Figure B).

Buildings Skyline Contour

The geometric information of each building is represented by a triplet of integers [Li, Ri, Hi], where Li and Ri are the x coordinates of the left and right edge of the ith building, respectively, and Hi is its height. It is guaranteed that 0 ≤ Li, Ri ≤ INT_MAX0 < Hi ≤ INT_MAX, and Ri - Li > 0. You may assume all buildings are perfect rectangles grounded on an absolutely flat surface at height 0.

For instance, the dimensions of all buildings in Figure A are recorded as: [ [2 9 10], [3 7 15], [5 12 12], [15 20 10], [19 24 8] ] .

The output is a list of "key points" (red dots in Figure B) in the format of [ [x1,y1], [x2, y2], [x3, y3], ... ] that uniquely defines a skyline. A key point is the left endpoint of a horizontal line segment. Note that the last key point, where the rightmost building ends, is merely used to mark the termination of the skyline, and always has zero height. Also, the ground in between any two adjacent buildings should be considered part of the skyline contour.

For instance, the skyline in Figure B should be represented as:[ [2 10], [3 15], [7 12], [12 0], [15 10], [20 8], [24, 0] ].

Notes:

  • The number of buildings in any input list is guaranteed to be in the range [0, 10000].
  • The input list is already sorted in ascending order by the left x position Li.
  • The output list must be sorted by the x position.
  • There must be no consecutive horizontal lines of equal height in the output skyline. For instance, [...[2 3], [4 5], [7 5], [11 5], [12 7]...] is not acceptable; the three lines of height 5 should be merged into one in the final output as such: [...[2 3], [4 5], [12 7], ...]
public class Solution {
	public static class Line implements Comparable<Line> {
		public int x;
		public boolean left;
		public int height;
		public Line(int x, int height, boolean left) {
            this.x = x;
            this.height = height;
            this.left = left;
        }
		@Override
		public int compareTo(Line o) {
			// TODO Auto-generated method stub
			if (x != o.x) {
				return x - o.x;
			}
			if (left != o.left) {
				if (left) {
					return -1;
				} else {
					return 1;
				}
			} else {
				if (left) {
					return o.height - height;
				} else {
					return height - o.height;
				}
			}
		}
		
	}
    public List<int[]> getSkyline(int[][] buildings) {
    	List<int[]> res = new ArrayList<>();
    	List<Line> lines = new ArrayList<>();
        for (int i = 0; i < buildings.length; i++) {
        	lines.add(new Line(buildings[i][0], buildings[i][2], true));
        	lines.add(new Line(buildings[i][1], buildings[i][2], false));
		}
        Collections.sort(lines);
        PriorityQueue<Integer> heap = new PriorityQueue<>(11, Collections.reverseOrder());
        for (Line line : lines) {
			if (line.left) {
				heap.add(line.height);
			} else {
				heap.remove(line.height);
			}
			int height = heap.size() == 0 ? 0 : heap.peek();
			if (line.height >= height) {
				int[] tmp = new int[]{line.x, height};
				if (res.size() == 0) {
					res.add(tmp);
				} else {
					int[] last = res.get(res.size()-1);
					if (tmp[1] != last[1]) {
						res.add(tmp);
					}
				}
			}
 		}
        return res;
    }
}

 

资源下载链接为: https://pan.quark.cn/s/abbae039bf2a 在计算机视觉领域,实时目标跟踪是许多应用的核心任务,例如监控系统、自动驾驶汽车和无人机导航等。本文将重点介绍一种在2017年备受关注的高效目标跟踪算法——BACF(Boosted Adaptive Clustering Filter)。该算法因其卓越的实时性和高精度而脱颖而出,其核心代码是用MATLAB编写的。 BACF算法全称为Boosted Adaptive Clustering Filter,是基于卡尔曼滤波器改进的一种算法。传统卡尔曼滤波在处理复杂背景和目标形变时存在局限性,而BACF通过引入自适应聚类和Boosting策略,显著提升了对目标特征的捕获和跟踪能力。 自适应聚类是BACF算法的关键技术之一。它通过动态更新特征空间中的聚类中心,更准确地捕捉目标的外观变化,从而在光照变化、遮挡和目标形变等复杂情况下保持跟踪的稳定性。此外,BACF还采用了Boosting策略。Boosting是一种集成学习方法,通过组合多个弱分类器形成强分类器。在BACF中,Boosting用于优化目标检测性能,动态调整特征权重,强化对目标识别贡献大的特征,从而提高跟踪精度。BACF算法在设计时充分考虑了计算效率,能够在保持高精度的同时实现快速实时的目标跟踪,这对于需要快速响应的应用场景(如视频监控和自动驾驶)至关重要。 MATLAB作为一种强大的数学计算和数据分析工具,非常适合用于算法的原型开发和测试。BACF算法的MATLAB实现提供了清晰的代码结构,方便研究人员理解其工作原理并进行优化和扩展。通常,BACF的MATLAB源码包含以下部分:主函数(实现整个跟踪算法的核心代码)、特征提取模块(从视频帧中提取目标特征的子程序)、聚类算法(实现自适应聚类过程)、Boosting算法(包含特征权重更新的代
内容概要:本书《Deep Reinforcement Learning with Guaranteed Performance》探讨了基于李雅普诺夫方法的深度强化学习及其在非线性系统最优控制中的应用。书中提出了一种近似最优自适应控制方法,结合泰勒展开、神经网络、估计器设计及滑模控制思想,解决了不同场景下的跟踪控制问题。该方法不仅保证了性能指标的渐近收敛,还确保了跟踪误差的渐近收敛至零。此外,书中还涉及了执行器饱和、冗余解析等问题,并提出了新的冗余解析方法,验证了所提方法的有效性和优越性。 适合人群:研究生及以上学历的研究人员,特别是从事自适应/最优控制、机器人学和动态神经网络领域的学术界和工业界研究人员。 使用场景及目标:①研究非线性系统的最优控制问题,特别是在存在输入约束和系统动力学的情况下;②解决带有参数不确定性的线性和非线性系统的跟踪控制问题;③探索基于李雅普诺夫方法的深度强化学习在非线性系统控制中的应用;④设计和验证针对冗余机械臂的新型冗余解析方法。 其他说明:本书分为七章,每章内容相对独立,便于读者理解。书中不仅提供了理论分析,还通过实际应用(如欠驱动船舶、冗余机械臂)验证了所提方法的有效性。此外,作者鼓励读者通过仿真和实验进一步验证书中提出的理论和技术。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值