zoukankan      html  css  js  c++  java
  • Lightoj 1016

    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 << 61;
    const double eps=1e-5;
    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=1;t<=T;t++){
            v.clear();
            cin>>n>>w;
            for(int i=1;i<=n;i++){
                cin>>x>>y;
                v.push_back(y);
            }
            sort(v.begin(),v.end());
            int k=v[0];
            ll ans=1;
            for(int i=1;i<v.size();i++){
                if(v[i]<=k+w)continue;
                else{
                    ans++;
                    k=v[i];
                }
            }
            printf("Case %d: %d
    ",t,ans);
        }
        return 0;
    }
  • 相关阅读:
    Exp4 恶意代码分析 20155223
    20155223 Exp3 免杀原理与实践 实验报告
    20155223 Exp2 后门原理与实践
    网络对抗第一次实验——PC平台逆向破解(5)M
    苏黄的假期学习报告3
    我的假期学习报告2
    苏黄永郦的假期报告——1
    20155223 《信息安全系统设计基础》课程总结
    2017-2018-1 20155223 《信息安全系统设计基础》第14周学习总结
    2017-2018-1 20155223 实验五 通讯协议设计
  • 原文地址:https://www.cnblogs.com/pk28/p/5598698.html
Copyright © 2011-2022 走看看