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;
	}
};
相关推荐
拳里剑气3 小时前
C++算法:多源BFS
c++·算法·宽度优先·多源bfs
ysa0510304 小时前
【板子】短序列dp(换成维护更小常数维度的dp)
c++·笔记·算法·板子
aramae6 小时前
C++ IO流完全指南:从C标准库到C++流式编程
服务器·c语言·开发语言·c++·后端
_wyt0016 小时前
c++里的族谱:树
c++·
@三十一Y7 小时前
C++:AVL树实现
c++
haolin123.8 小时前
类和对象(上)
开发语言·c++
ShineWinsu8 小时前
对于Linux:传输层协议UDP原理的解析
linux·c++·面试·udp·协议·传输层·计算机系统
LingzhiPi8 小时前
零知派ESP32--AS5600磁吸旋钮音量控制器
c++·单片机·嵌入式硬件
小保CPP8 小时前
OpenCV C++车型识别1-图像预处理
c++·人工智能·opencv·计算机视觉
库克克8 小时前
【C++】C++11 包装器function 与 绑定器 bind
开发语言·c++