lightoj 1016 - Brush (II) 【贪心】
来源:互联网 发布:js隐藏span 编辑:程序博客网 时间:2024/06/05 01:02
题目链接:lightoj 1016 - Brush (II)
1016 - Brush (II)
PDF (English) Statistics Forum
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.
题意:每次可以涂掉宽w的水平带,问你最少多少次涂完。
贪心就好了。。。
AC代码:
#include <cstdio>#include <cstring>#include <algorithm>#include <map>#include <iostream>#include <cmath>#include <queue>#include <stack>#define ll o<<1#define rr o<<1|1#define CLR(a, b) memset(a, (b), sizeof(a))using namespace std;typedef long long LL;typedef pair<int, int> pii;const int INF = 0x3f3f3f3f;const int MAXN = 5*1e5 + 10;int x[MAXN], y[MAXN], pos[MAXN], rec[MAXN];int main(){ int t, kcase = 1; scanf("%d", &t); while(t--) { int n, w; scanf("%d%d", &n, &w); int top = 0; for(int i = 1; i <= n; i++) { scanf("%d%d", &x[i], &y[i]); rec[top++] = y[i]; } sort(rec, rec+top); int N = unique(rec, rec+top) - rec; for(int i = 1; i <= n; i++) { int p = lower_bound(rec, rec+N, y[i]) - rec; pos[p] = y[i]; } int ans = 0; rec[N] = INF; for(int i = 0; i < N; ) { int W = w + pos[i] + 1; ans++; int j = lower_bound(rec+i, rec+N+1, W) - rec; i = j; } printf("Case %d: %d\n", kcase++, ans); } return 0;}
- lightoj 1016 - Brush (II) 贪心
- lightoj 1016 - Brush (II) 【贪心】
- LightOJ - 1016 Brush (II)(贪心)
- LightOJ 1016 Brush (II)
- LightOJ-1016-Brush (II)
- LightOJ 1016 Brush (II) 思路
- LightOJ - 1016 Brush (II) (模拟)水
- LightOJ1016---Brush (II) (贪心)
- LIGHTOJ 1018 Brush (IV)
- LightOJ - 1019 Brush (V)
- lightoj 1017 - Brush (III)
- LightOJ - 1017 Brush (III)
- LightOJ 1018 Brush (IV)
- LightOJ 1019 Brush (V)
- LightOJ 1017 - Brush (III)
- LightOJ 1017 - Brush (III)
- LightOJ 1018 - Brush (IV)
- LightOJ 1017 Brush (III)
- 怎么在ZBrush中渲染漫画风格的插画
- SwipeRefreshLayout与viewpager的滑动冲突的解决
- block、inline和inline-block概念和区别
- 递推求阶乘
- maven管理本地jar包
- lightoj 1016 - Brush (II) 【贪心】
- BZOJ 2337|HNOI 2011|XOR和路径|概率期望|高斯消元
- QDockWidget嵌套布局详解-实现Visual Studio布局
- 利用listview实现简要的QQ聊天效果
- id、静态类型、自省-iOS初学
- C#界面设计之菜单栏的使用
- iOS屏幕旋转
- Could not read symbols解决方法
- maven