Saturday, December 5, 2020

 LightOJ-1016 - Brush (II) 

 IDEA: 

We can clean each dust by placing the brush on the y-axis of that point. From that point +w will cover all the points between them inclusively. For this first sort y-axis value then find points covered by each point.

Code:

//
// Created by Dabashis Kundu Shento on 5/12/20.
//

#include <bits/stdc++.h>

using namespace std;

int main() {
int t,l=0;
cin>>t;
while(t--)
{
l++;
int n,w;
cin>>n>>w;
int a,b;
int c,d;
vector<int> v;
for(int i=0;i<n;i++)
{
cin>>a>>b;
v.push_back(b);
}
sort(v.begin(),v.end());
int ans=1;
c=v[0];
for(int i=1;i<n;i++)
{
if(v[i]-c>w)
{
ans++;
c=v[i];
}
}
cout<<"Case "<<l<<": "<<ans<<endl;
}
return 0;
}

 

 

No comments:

Post a Comment