zoukankan      html  css  js  c++  java
  • poj 3258

    River Hopscotch
    Time Limit: 2000MS Memory Limit: 65536K
    Total Submissions: 3659 Accepted: 1587

    Description

    Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a rock at the start and another rock at the end, L units away from the start (1 ≤ L ≤ 1,000,000,000). Along the river between the starting and ending rocks, N (0 ≤ N ≤ 50,000) more rocks appear, each at an integral distance Di from the start (0 < Di <L).

    To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping only from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river.

    Farmer John is proud of his cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rocks placed too closely together. He plans to remove several rocks in order to increase the shortest distance a cow will have to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he has enough resources to remove up to rocks (0 ≤ M ≤ N).

    FJ wants to know exactly how much he can increase the shortest distance *before* he starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow has to jump after removing the optimal set of M rocks.

    Input

    Line 1: Three space-separated integers: LN, and M 
    Lines 2..N+1: Each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position.

    Output

    Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks

    Sample Input

    25 5 2
    2 14 11 21 17

    Sample Output

    4
    题意:一条直线上有很多石头,问去掉一定数量的石头使得最小距离最大。
    sl:很显然的二分,就是怎么判断想了2分钟,太水了有点,其实直接贪心的删去最右边的石头就好了。
     1 //二分+贪心每次取右边的
     2 //by zyq
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<algorithm>
     6 using namespace std;
     7 const int MAX = 50000+10;
     8 int d[MAX];
     9 int l,n,m;
    10 
    11 int check(int Max_d)
    12 {
    13     int tot=0int st=0;
    14     for(int i=0;i<n;i++)
    15     {
    16         if(d[i]-st<Max_d) tot++;
    17         else st=d[i];
    18     }
    19     if(l-st<Max_d) tot++;
    20     return tot<=m;
    21 }
    22 
    23 int main()
    24 {
    25     int ans;
    26     while(scanf("%d %d %d",&l,&n,&m)==3)
    27     {
    28 
    29         for(int i=0;i<n;i++) scanf("%d",&d[i]);
    30         sort(d,d+n);
    31         int L=1int R=l;
    32         while(L<=R)
    33         {
    34             int mid=(L+R)>>1;
    35             if(check(mid)) ans=mid,L=mid+1;
    36             else R=mid-1;
    37         }
    38         printf("%d ",ans);
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    堆和栈的区别
    今天开通博客了!
    【转】Perl中的正则表达式
    【转】Windows server 2008远程桌面轻松搞定
    【转】彻底删除0KB顽固文件或文件夹的方法
    【转】Java URL Encoding and Decoding
    【转】一个女留学生在美国的七年
    【转】风雨20年:我所积累的20条编程经验
    【转】深入浅出REST
    【转】Python正则表达式指南
  • 原文地址:https://www.cnblogs.com/acvc/p/3661079.html
Copyright © 2011-2022 走看看