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;
	}
};
相关推荐
hPw0eKIqD12 小时前
C++ 模板参数推导问题小记(非推导上下文)
开发语言·c++
程序员爱德华12 小时前
Python与C++:异同点对比
c++·python
888CC++15 小时前
C语言与C++的区别:从面向过程到面向对象
java·c语言·c++
Darkwanderor17 小时前
Linux系统编程实战项目:模拟实现shell
linux·c++
himobrinehacken17 小时前
揭秘Windows程序启动的神秘之旅
c++·安全
库玛西18 小时前
C++ 运行时多态 :核心总结与原理图解
c语言·c++·笔记
Byron Loong19 小时前
【C++】重定向是什么
开发语言·c++
hansang_IR19 小时前
【题解】LC:Z 算法(Z Algorithm)
c++·算法·字符串
霍霍的袁21 小时前
【C++】模板从入门到进阶(函数模板 + 类模板 + 特化 + 分离编译)
开发语言·c++·visual studio
海清河晏11121 小时前
Qt 实战:信号与槽+事件系统
开发语言·c++·qt