题目链接:点击打开链接
水题,简单模拟...
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
const int N = 50100;
int n,w;
int a[N];
ll solve()
{
ll ans = 1;
ll h = a[0]+w;
for (int i = 1; i < n; i++)
{
if (a[i] <= h)
continue;
ans++;
h =a[i] + w;
}
return ans;
}
int main()
{
int test;
scanf("%d", &test);
int x, y;
for (int cas = 1; cas <= test; cas++)
{
scanf("%d%d", &n, &w);
for (int i = 0; i < n; i++)
scanf("%d%d", &x, &a[i]);
sort(a, a + n);
printf("Case %d: %lld\n", cas, solve());
}
return 0;
}