1016 - Brush (II)
Time Limit: 2 second(s) Memory Limit: 32 MB

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: xi yi,denoting 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

Note

Data set is huge, so use faster I/O methods.


PROBLEM SETTER: MUHAMMAD RIFAYAT SAMEE
SPECIAL THANKS: JANE ALAM JAN (DESCRIPTION, SOLUTION, DATASET)
思路:二分;
先把每个点能覆盖到的前面点的最小的那个用二分找出来。然后存在id[i]中,
然枚举每个点,dp[i]=dp[id[i]-1]+1;贪心的选取每个点能覆盖到的前面的最大范围。
 1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<iostream>
4 #include<algorithm>
5 #include<string.h>
6 #include<queue>
7 #include<stack>
8 #include<math.h>
9 #include<vector>
10 using namespace std;
11 typedef struct pp
12 {
13 int x;
14 int y;
15 }ss;
16 ss dd[500006];
17 int id[500006];
18 int dp[500006];
19 bool cmp(pp p,pp q)
20 {
21 return p.y<q.y;
22 }
23 int main(void)
24 {
25 int i,j,k;
26 scanf("%d",&k);
27 int s;
28 for(s=1;s<=k;s++)
29 { int n,m;
30 scanf("%d %d",&n,&m);
31 for(i=1;i<=n;i++)
32 {
33 scanf("%d %d",&dd[i].x,&dd[i].y);
34 }
35 sort(dd+1,dd+n+1,cmp);
36 id[0]=0;id[1]=1;
37 for(i=2;i<=n;i++)
38 {
39 int l=0;int r=i;
40 int ik=-1;
41 while(l<=r)
42 {
43 int mid=(l+r)/2;
44 if(dd[mid].y+m>=dd[i].y)
45 {
46 ik=mid;
47 r=mid-1;
48 }
49 else l=mid+1;
50 }
51 id[i]=ik;
52 }
53 fill(dp,dp+500006,1e9);
54 dp[0]=0;
55 for(i=1;i<=n;i++)
56 {
57 dp[i]=dp[id[i]-1]+1;
58 }
59 printf("Case %d: %d\n",s,dp[n]);
60 }
61 return 0;
62 }

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

  1. Lightoj 1016 - Brush (II)

    After the long contest, Samee returned home and got angry after seeing his room dusty. Who likes to ...

  2. lightoj刷题日记

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

  3. one recursive approach for 3, hdu 1016 (with an improved version) , permutations, N-Queens puzzle 分类: hdoj 2015-07-19 16:49 86人阅读 评论(0) 收藏

    one recursive approach to solve hdu 1016, list all permutations, solve N-Queens puzzle. reference: t ...

  4. 洛谷 1016 / codevs 1046 旅行家的预算

    https://www.luogu.org/problem/show?pid=1016 http://codevs.cn/problem/1046/ 题目描述 Description 一个旅行家想驾驶 ...

  5. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  6. Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II

    题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...

  7. 【转】c#、wpf 字符串,color,brush之间的转换

    转自:http://www.cnblogs.com/wj-love/archive/2012/09/14/2685281.html 1,将#3C3C3C 赋给background this.selec ...

  8. 函数式Android编程(II):Kotlin语言的集合操作

    原文标题:Functional Android (II): Collection operations in Kotlin 原文链接:http://antonioleiva.com/collectio ...

  9. 统计分析中Type I Error与Type II Error的区别

    统计分析中Type I Error与Type II Error的区别 在统计分析中,经常提到Type I Error和Type II Error.他们的基本概念是什么?有什么区别? 下面的表格显示 b ...

随机推荐

  1. Python序列化,json&pickle&shelve模块

    1. 序列化说明 序列化可将非字符串的数据类型的数据进行存档,如字典.列表甚至是函数等等 反序列化,将通过序列化保存的文件内容反序列化即可得到数据原本的样子,可直接使用 2. Python中常用的序列 ...

  2. A Child's History of England.36

    CHAPTER 11 ENGLAND UNDER MATILDA AND STEPHEN The King was no sooner dead than all the plans and sche ...

  3. day03 部署NFS服务

    day03 部署NFS服务 NFS的原理 1.什么是NFS 共享网络文件存储服务器 2.NFS的原理 1.用户访问NFS客户端,将请求转化为函数 2.NFS通过TCP/IP连接服务端 3.NFS服务端 ...

  4. JDK1.8新特性(一): 接口的默认方法default

    前言 今天在学习mysql分区优化时,发现一个博客专家大神,对其发布的文章简单学习一下: 一:简介 我们通常所说的接口的作用是用于定义一套标准.约束.规范等,接口中的方法只声明方法的签名,不提供相应的 ...

  5. CentOS 7.3安装完整开发环境

    系统版本CentOS 7.3(1611) 安装开发环境1) 通过group安装 yum groups mark install "Development Tools" yum gr ...

  6. Oracle trunc和round的区别

    1.关于trunc 和round函数比较 整体概括: round函数 四舍五入trunc函数 直接截取 对于时间: Round函数对日期进行"四舍五入",Trunc函数对日期进行截 ...

  7. Spring标签库

    spring提供了两个标签库文件:spring-form.tld(表单标签库,用于输出HTML表单)  spring.tld(基础标签库,用于Spring数据绑定等) 使用步骤: 1,配置表单标签库, ...

  8. 【力扣】337. 打家劫舍 III

    在上次打劫完一条街道之后和一圈房屋后,小偷又发现了一个新的可行窃的地区.这个地区只有一个入口,我们称之为"根". 除了"根"之外,每栋房子有且只有一个" ...

  9. Nginx配置重定向

    目录 一.简介 二.配置 访问a页面重定向到b页面 访问当前nginx,重定向到其他网址 一.简介 据相关变量重定向和选择不同的配置,从一个 location 跳转到另一个 location,不过这样 ...

  10. JS 中常用的去重

    第一种:indexOf (获取字符串值在字符串中首次出现的位置,若没有这个值,则返回-1) let arr = [15,45,88,45,78,15,55,88]; let arr1 = []; // ...