- 做第一题的时候就感觉到和平常的周赛难度不一样了
- 用合并区间做的
- 花了大概 10 分钟
class Solution {
public:
int numberOfPoints(vector<vector<int>>& nums) {
int res = 0;
sort(nums.begin(), nums.end());
vector<vector<int>> cnt;
int n = nums.size();
int idx = 0;
while (idx < n) {
int l = nums[idx][0], r = nums[idx][1];
int i = idx + 1;
for (; i < n; i ++) {
int l_t = nums[i][0], r_t = nums[i][1];
if (l_t > r) {
break; // 超过了 区间
}
if (r_t > r) r = r_t; // 更新区间
}
idx = i;
cnt.push_back({l, r});
}
for (int i = 0; i < cnt.size(); i ++) res += (cnt[i][1] - cnt[i][0] + 1);
return res;
}
};
- 思路一下跑偏了 不知道当时怎么想的 结果越跑越偏
- 用 dfs 做的 -> 数据范围 $10^9$ 必然超时
- 其实这个不是特别难
- 止步于此
class Solution {
public:
bool isReachableAtTime(int sx, int sy, int fx, int fy, int t) {
// 数据有点大
long long dx = abs(fx - sx);
long long dy = abs(fy - sy);
if (dx == 0 && dy == 0) return t != 1;
return max(dx, dy) <= t;
}
};