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;
	}
};
相关推荐
WL学习笔记23 分钟前
类和对象(下)
c++·类和对象
傲世仙尊1 小时前
拷贝构造-传值传参的连锁反应与隐式函数的三个局限
c++
垆边人似月.1 小时前
华为机试题 :最大数
c++·算法·华为
方便面不加香菜2 小时前
C++ 关于多态的知识点讲解
开发语言·c++
jimy12 小时前
C++ 类成员函数的内联定义(inline)详解
开发语言·c++
sanqima2 小时前
CreateThread、_beginthreadex、AfxBeginThread三种线程创建的区别与联系
c++·tls·线程创建
sanqima3 小时前
依赖TLS和模块状态的MFC类
c++·mfc·tls·module state
All for pursuit.3 小时前
【动态规划-11】279.完全平方数
数据结构·c++·算法·leetcode·动态规划
瑶山3 小时前
Windows + WSL2 Ubuntu + VS Code配置C++开发环境
开发语言·c++·windows·vscode·wsl
小米里的大麦3 小时前
19 C、C++ 操作 MySQL
c语言·c++·mysql