LightOJ - 1016 Brush (II) (模拟)水

39 篇文章 0 订阅
LightOJ - 1016
Time Limit: 2000MSMemory Limit: 32768KB64bit IO Format: %lld & %llu

Submit Status

Description

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 yidenoting 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

2

 

3 2

0 0

20 2

30 2

 

3 1

0 0

20 2

30 2

Sample Output

Case 1: 1

Case 2: 2

Source

Problem Setter: Muhammad Rifayat Samee
Special Thanks: Jane Alam Jan (Description, Solution, Dataset)
//题意:
给你一个n,表示有n个点,再给出一个w表示一个刷子的宽度(刷子平行于x轴刷),问最少刷几次可以把所有点刷完
//思路:
直接模拟就行了,水题
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ll long long
#define IN __int64
#define N 50010
#define M 1000000007
using namespace std;
struct zz
{
	int x;
	int y;
}p[N];
bool cmp(zz a,zz b)
{
	if(a.y==b.y)
		return a.x<b.x;
	return a.y<b.y;
}
int main()
{
	int T=1,t,n,m,i,j,k;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&m);
		for(i=0;i<n;i++)
			scanf("%d%d",&p[i].x,&p[i].y);
		sort(p,p+n,cmp);
		int cnt=0;
		int jj=0;
		for(i=1;i<n;i++)
		{
			j=p[jj].y;
			k=j+m;
			if(p[i].y<=k)
				continue;
			else
			{
				cnt++;
				jj=i;
			}
		}
		printf("Case %d: %d\n",T++,cnt+1);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值