首页 > 其他分享 >Destroyer Takahashi

Destroyer Takahashi

时间:2023-01-07 00:12:37浏览次数:70  
标签:std const Destroyer int ll second pll 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;
}

标签:std,const,Destroyer,int,ll,second,pll,Takahashi
From: https://www.cnblogs.com/Zeoy-kkk/p/17031971.html

相关文章

  • [ABC233G] Strongest Takahashi
    ProblemStatementThereisa$N\timesN$grid,withblocksonsomesquares.Thegridisdescribedby$N$strings$S_1,S_2,\dots,S_N$,asfollows.Ifthe$j$-t......
  • D - Takahashi's Solitaire -- ATCODER
    D-Takahashi'sSolitairehttps://atcoder.jp/contests/abc277/tasks/abc277_d 思路先计算所有的输入的和total,将输入列表首先进行排列找到所有连续段和中最大的......
  • C - Ladder Takahashi -- ATCODER
    C-LadderTakahashihttps://atcoder.jp/contests/abc277/tasks/abc277_c 思路把梯子可达楼层看成图的节点把梯子看成节点之间的连线所以整个问题变成图的遍历问题......
  • AtCoder Beginner Contest 277 D Takahashi's Solitaire
    Takahashi'sSolitaire双指针&&尺取先排个序,然后把数组扩展到\(2\timesn\),为了处理循环的情况然后双指针跑一下,限定\(r\)扩展的条件为:当前数字等于前一个或者......