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;
	}
};
相关推荐
·present·8 小时前
CSAPP(lecture 4_01)
c语言·c++
FPGA小迷弟9 小时前
用 Claude Code 重构遗留系统:从评估到落地的完整实践指南
c++·python·ai·plotly·django·ai编程·claude
程序员-King.9 小时前
【ROS1】Noetic 开发工作流程与常用命令
c++·ubuntu·ros
云深麋鹿9 小时前
C++ | 基于红黑树实现mymap与myset
开发语言·c++
傲世仙尊11 小时前
string增删查改-insert-erase-replace与find加substr组合技
c++
·present·12 小时前
CSAPP(lecture 3)
c++
别动我齐刘海13 小时前
机器人 C++ / 系统联调补强2——异常处理、Protobuf
linux·c++·人工智能·学习·算法·机器学习·机器人
basketball61613 小时前
C++ 中字符串与常见类型的转换总结
开发语言·c++
等我调个Bug13 小时前
C++智能指针通俗讲解
开发语言·c++
kyle~15 小时前
时间同步 --- PTP 与 Scheduled Action Command
c++·数码相机·机器人·传感器