Destroyer Takahashi

Destroyer Takahashi


题解:区间选点问题

这里面他又给出了D,D其实可以代表他从右端点还可以往外延申D-1 的长度,实际上每次的\(now=a[i].r+D-1\)

#include <bits/stdc++.h>
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 2e5 + 10;
pll a[N];
int cmp(pll x, pll y)
{
    return x.second < y.second;
}
int main(void)
{
    Zeoy;
    int t = 1;
    // cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        ll d;
        cin >> d;
        for (int i = 1; i <= n; ++i)
            cin >> a[i].first >> a[i].second;
        sort(a + 1, a + 1 + n, cmp);
        ll now = a[1].second + d - 1;
        ll ans = 1;
        for (int i = 2; i <= n; ++i)
        {
            if (a[i].first > now)
            {
                ans++;
                now = a[i].second + d - 1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}
posted @ 2023-01-06 23:59  Zeoy_kkk  阅读(21)  评论(0编辑  收藏  举报