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 ;
}

Lightoj 1016 - Brush (II)的更多相关文章

  1. 1016 - Brush (II)

    1016 - Brush (II)    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Afte ...

  2. lightOJ 1017 Brush (III) DP

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...

  3. LightOJ 1017 - Brush (III) 记忆化搜索+细节

    http://www.lightoj.com/volume_showproblem.php?problem=1017 题意:给出刷子的宽和最多横扫次数,问被扫除最多的点是多少个. 思路:状态设计DP[ ...

  4. [LightOJ 1018]Brush (IV)[状压DP]

    题目链接:http://lightoj.com/volume_showproblem.php? problem=1018 题意分析:平面上有不超过N个点,如今能够随意方向划直线将它们划去,问:最少要划 ...

  5. Lightoj 1018 - Brush (IV)

    1018 - Brush (IV)    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Muba ...

  6. Lightoj 1017 - Brush (III)

    1017 - Brush (III)    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Sam ...

  7. lightoj 1016

    水题,排个序直接搞. #include<cstdio> #include<string> #include<cstring> #include<iostrea ...

  8. Lightoj 1019 - Brush (V)

    算出从点1到点n的最短路径. /* *********************************************** Author :guanjun Created Time :2016 ...

  9. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

随机推荐

  1. 【BZOJ 3555】 [Ctsc2014]企鹅QQ(哈希)

    Description PenguinQQ是中国最大.最具影响力的SNS(Social Networking Services)网站,以实名制为基础,为用户提供日志.群.即时通讯.相册.集市等丰富强大 ...

  2. Mybatis 缓存策略

    听极客学院笔记 使用mybatis的缓存需要以下三步 一.在mybatis的config.xml中开启缓存 <settings> <setting name="cacheE ...

  3. Coloring Brackets (区间DP)

    Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a soluti ...

  4. android L版本AAL新架构

    [DESCRIPTION] 和之前KK版本相比,在L版本上面AAL的架构也有发生一些改变. 拿掉了之前KK平台上使用的MTK LABC,使用Android原生的自动背光功能. AALService内部 ...

  5. 使用DataOutputStream输出流的read方法出现读取字节不一致解决办法,本地和测试环境不一致

    之前: DataInputStream in = new DataInputStream(connection.getInputStream());    byte[] b = new byte[in ...

  6. excludepathpatterns 无效

    踩坑了,调了好久才调出来. 原因:  访问的API /XXX 已经转换为 /error 了.  把“/error” 也加入 excludepathpatterns 里面即可.

  7. RabbitMQ最佳实践

    在使用消息机制时,我们通常需要考虑以下几个问题: 消息不能丢失 保证消息一定能投递到目的地 保证业务处理和消息发送/消费的一致性 本文以RabbitMQ为例,讨论如何解决以上问题. 消息持久化 如果希 ...

  8. codeforces 873F(后缀数组)

    题意 给一个长度不超过200000的字符串s,假定有一个字符串a,这个字符串在s中出现次数是f(a),你需要让$|a|f(a)$最大. 但是有一些位置是禁止的,即以该位置为结束位置的字符串不计数. 分 ...

  9. 从Java代码到字节码

    http://www.importnew.com/13107.html http://blog.csdn.net/dc_726/article/details/7944154/ http://www. ...

  10. how to read openstack code: loading process

    之前我们了解了neutron的结构,plugin 和 extension等信息.这一章我们看一下neutron如何加载这些plugin和extension.也就是neutron的启动过程.本文涉及的代 ...