After the long contest, Samee returned home and got angry after seeing his room dusty. Who likes to see a dusty room after a brain storming programming contest? After checking a bit he found a brush in his room which has width w. Dusts are defined as 2D points. And since they are scattered everywhere, Samee is a bit confused what to do. So, he attached a rope with the brush such that it can be moved horizontally (in X axis) with the help of the rope but in straight line. He places it anywhere and moves it. For example, the y co-ordinate of the bottom part of the brush is 2 and its width is 3, so the y coordinate of the upper side of the brush will be 5. And if the brush is moved, all dusts whose y co-ordinates are between 2 and 5 (inclusive) will be cleaned. After cleaning all the dusts in that part, Samee places the brush in another place and uses the same procedure. He defined a move as placing the brush in a place and cleaning all the dusts in the horizontal zone of the brush.

You can assume that the rope is sufficiently large. Now Samee wants to clean the room with minimum number of moves. Since he already had a contest, his head is messy. So, help him.

Input

Input starts with an integer T (≤ 15), denoting the number of test cases.

Each case starts with a blank line. The next line contains two integers N (1 ≤ N ≤ 50000) and w (1 ≤ w ≤ 10000), means that there are N dust points. Each of the next N lines will contain two integers: xiyidenoting coordinates of the dusts. You can assume that (-109 ≤ xi, yi ≤ 109) and all points are distinct.

Output

For each case print the case number and the minimum number of moves.

Sample Input

Output for Sample Input

2

3 2

0 0

20 2

30 2

3 1

0 0

20 2

30 2

Case 1: 1

Case 2: 2

题意:一个刷子一次 可以刷掉横坐标-INF~+INF 宽度为w上的任意点。现在有一些点需要刷掉。问最少刷几次。刷子宽度w。

贪心:

/* ***********************************************
Author :guanjun
Created Time :2016/6/19 19:11:25
File Name :1016.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1<<30
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
vector<int>v;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int T,a,n,x,y;
ll w;
cin>>T;
for(int t=;t<=T;t++){
v.clear();
cin>>n>>w;
for(int i=;i<=n;i++){
cin>>x>>y;
v.push_back(y);
}
sort(v.begin(),v.end());
int k=v[];
ll ans=;
for(int i=;i<v.size();i++){
if(v[i]<=k+w)continue;
else{
ans++;
k=v[i];
}
}
printf("Case %d: %d\n",t,ans);
}
return ;
}

最新文章

  1. 学习php一个星期
  2. C#webform LinQ
  3. JSTL函数
  4. 一个winform带你玩转rabbitMQ
  5. C#控制管理VisualSVN Server 分类: C# 2014-05-29 15:51 796人阅读 评论(0) 收藏
  6. Linux vi 中移动光标 命令
  7. XML序列化中含有List的情况,序列化到根节点下一层
  8. 将网站部署到windows2003 iis6之后,出现asp.net程序页面无法访问情况
  9. tomcat中的get、post区别
  10. XML Helper XML操作类
  11. android自定义View之仿通讯录侧边栏滑动,实现A-Z字母检索
  12. org.springframework.web.context.ContextLoaderListener 转
  13. 数学计数原理(P&#243;lya,高精度):SGU 294 He&#39;s Circles
  14. BPM7.5.1升级细节,万事开头难
  15. Bootstrap Paginator分页插件+ajax 实现动态无刷新分页
  16. MongoDB 关系
  17. js语言规范_ES5-6-7_个人总结
  18. 引用变量&amp;和指针*的区别
  19. EasyPR源码剖析(4):车牌定位之Sobel算子定位
  20. 如何避免form提交进行页面跳转

热门文章

  1. 关于hibernate中的 lazy=&quot;false“
  2. jmeter给cookie设置sessionId避免其他脚本多次登录
  3. HDU 5421 Victor and String
  4. Java有几种线程池?
  5. Codeforces Manthan, Codefest 18 (rated, Div. 1 + Div. 2) D,E
  6. CodeForces 596A Wilbur and Swimming Pool
  7. HDU——2119 Matrix
  8. SVN 更新后Tomcat 启动时出现问题
  9. jenkins修改日志级别方法
  10. Redis 命令行 常用总结