一、区间问题
Leetcode 3111.覆盖所有点的最少矩形数目
class Solution {
public:
int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {
int n = points.size();
long long res = 0;
sort(points.begin(), points.end(), [&](const vector<int>& a, const vector<int>& b) -> bool{
return a[0] < b[0];
}); // 按照x坐标进行排序
int st = points[0][0];
int cur_l = st, cur_r = cur_l + w; res ++;
for (int i = 0; i < n; i ++){
if (points[i][0] <= cur_r) continue;
// 否则需要新开一个区间
cur_r = points[i][0] + w; res ++;
}
return res;
}
};