Lightoj 1016 - Brush (II)
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: xiyi, 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 |
题意:一个刷子一次 可以刷掉横坐标-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)的更多相关文章
- 1016 - Brush (II)
1016 - Brush (II) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Afte ...
- lightOJ 1017 Brush (III) DP
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...
- LightOJ 1017 - Brush (III) 记忆化搜索+细节
http://www.lightoj.com/volume_showproblem.php?problem=1017 题意:给出刷子的宽和最多横扫次数,问被扫除最多的点是多少个. 思路:状态设计DP[ ...
- [LightOJ 1018]Brush (IV)[状压DP]
题目链接:http://lightoj.com/volume_showproblem.php? problem=1018 题意分析:平面上有不超过N个点,如今能够随意方向划直线将它们划去,问:最少要划 ...
- Lightoj 1018 - Brush (IV)
1018 - Brush (IV) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Muba ...
- Lightoj 1017 - Brush (III)
1017 - Brush (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Sam ...
- lightoj 1016
水题,排个序直接搞. #include<cstdio> #include<string> #include<cstring> #include<iostrea ...
- Lightoj 1019 - Brush (V)
算出从点1到点n的最短路径. /* *********************************************** Author :guanjun Created Time :2016 ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
随机推荐
- POJ 1949 Chores(DAG上的最长路 , DP)
题意: 给定n项任务, 每项任务的完成用时t和完成每项任务前需要的k项任务, 求把所有任务完成的最短时间,有当前时间多项任务都可完成, 那么可以同时进行. 分析: 这题关键就是每项任务都会有先决条件, ...
- sysctl.conf文件配置详解
############################# net.inet.ip.sourceroute=0 net.inet.ip.accept_sourceroute=0 ########### ...
- 65.什么是IOC?【从零开始学Spring Boot】
[从零开始学习Spirng Boot-常见异常汇总] 这个小节吧,是无意当中看了一篇文章,觉得介绍的特别好,引用到我的博客中,让大家也乐下.那么他是怎么解说IOC的呢?看如下: 套用好莱坞的一句名言就 ...
- ms sqlserver数据库建索引
索引分类:从物理结构上可分为两种:聚集索引和非聚集索引 (此外还有空间索引.筛选索引.XML索引) 因为聚集索引是索引顺序与物理存储顺序一致,所以只能建一个. 聚集索引就是把数据按主键顺序存储: 因为 ...
- 关于srand()rand()的用法
转自:http://baike.baidu.com/link?url=bhos65ZKp8lEq_6chSsmQv29jHrqjN_IFGVMNod6BuicQ-3oCP5VsEn3RBjXBPvA7 ...
- hdu 2845
#include<stdio.h> #define N 200100 int f[N]; int a[N],n; int main() { int m,j,i,suma,sumb,sum ...
- django学习之- 信号
- Django内置的信号Model signals pre_init # django的modal执行其构造方法前,自动触发 post_init # django的modal执行其构造方法后,自动触 ...
- React学习及实例开发(三)——用react-router跳转页面
本文基于React v16.4.1 初学react,有理解不对的地方,欢迎批评指正^_^ 一.定义路由 1.安装react-router npm install react-router@ --sav ...
- 压力测试webbench(转)
最近app需要搭建后台,故此研究一下,靠谱的后台服务器..网传nginx 能达到的并发数量比apache 高. LAMP or LNMP ? 根据需求测试结果来进行选择. 首先是安装LNMP测试完后 ...
- [Bzoj2039]小Z的袜子 (莫队算法模板题)
2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 11866 Solved: 5318[Sub ...