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;
	}
};
相关推荐
Qt程序员2 小时前
Linux RCU 原理与应用
linux·c++·内核·linux内核·rcu
qeen873 小时前
【C++】类与对象之类的默认成员函数(二)
android·c语言·开发语言·c++·笔记·学习
王老师青少年编程3 小时前
信奥赛C++提高组csp-s之搜索进阶(记忆化搜索案例实践3)
c++·记忆化搜索·方格取数·csp·信奥赛·csp-s·提高组
Titan20244 小时前
Linux动静态库
linux·服务器·c++
j_xxx404_5 小时前
MySQL表操作硬核解析:从 CREATE TABLE 到磁盘文件、ALTER TABLE 与 DDL 风险
运维·服务器·数据库·c++·mysql·adb·ai
wuminyu5 小时前
Java锁机制之park和unpark源码剖析
java·linux·c语言·jvm·c++
玖玥拾6 小时前
C/C++ 基础笔记(十一)类的进阶
c语言·c++·设计模式·
-森屿安年-6 小时前
1137. 第 N 个泰波那契数
c++·动态规划
程序员老舅7 小时前
从内核视角,看Linux文件读写过程
linux·服务器·c++·内核·linux内核·vfs·linux内存
Soari7 小时前
llama.cpp更新(b9553):LLM inference in C/C++,本地和云端实现高性能大模型推理
c语言·c++·llama