3111. 覆盖所有点的最少矩形数目

3111. 覆盖所有点的最少矩形数目


题目链接:3111. 覆盖所有点的最少矩形数目

代码如下:

cpp 复制代码
class Solution 
{
public:
	int minRectanglesToCoverPoints(vector<vector<int>>& points, int w)
	{
		sort(points.begin(), points.end(), [](const auto& a, const auto& b)->bool
			{
				return a[0] < b[0];//升序排序
			});
		int res = 0;
		int x2 = -1;
		for (const auto& p : points)
		{
			if (p[0] > x2)
			{
				res++;
				x2 = p[0] + w;
			}
		}
		return res;
	}
};
相关推荐
疋瓞27 分钟前
python和C++对比(1)_数据类型和数据结构
数据结构·c++·python
C语言小火车39 分钟前
C++ 堆排序深度精讲:基于完全二叉树的选择排序进化,最坏情况 O(n log n) 的稳定王者
开发语言·c++·算法·排序算法·堆排序
ALex_zry2 小时前
C++26 std::complex 结构化绑定详解:auto [re, im] = c
c语言·开发语言·c++
_olone3 小时前
Luogu P2704 [NOI2001] 炮兵阵地
c++·算法·状压dp
c238563 小时前
互斥锁高频面试题全解:从基础概念到底层实现,一文通关
java·c++·面试·职场和发展
nianniannnn3 小时前
c++复习自存--继承
开发语言·c++
王老师青少年编程5 小时前
2026年6月GESP真题及题解(C++二级):完全平方数计数
c++·题解·真题·gesp·二级·2026年6月·完全平方数计数
zwenqiyu5 小时前
非线性字符串数据结构串讲
数据结构·c++·学习·算法
CodeStats5 小时前
【编程语言】深度梳理C/C++、Java、Python、Go、Rust的区别
java·linux·c语言·c++·python·rust·go
努力中的编程者6 小时前
STL-vector的模拟实现
开发语言·c++·算法·stl·vector