zoukankan      html  css  js  c++  java
  • 1016

    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
    ",s,dp[n]);
    60     }
    61     return 0;
    62 }
    油!油!you@
  • 相关阅读:
    OSPF的简易模拟配置第二篇
    OSPF的简易模拟配置第一篇
    RIP简易配置第二篇
    linux常用命令集(压缩和归档操作-共16个)
    简易路由重分布配置
    linux常用命令集(磁盘和文件系统操作-共15个)
    简易的浮动静态路由配置
    神州数码DHCP及DHCP中继配置
    神州数码HSRP(热备份路由协议)配置
    神州数码策略路由(PBR)配置
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/5612825.html
Copyright © 2011-2022 走看看