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 }
  • 相关阅读:
    FontAwesome动态旋转图标类(fa-spin&fa-pulse)
    心得体悟帖---200401(录课异常状态可以试讲,且一定试讲,然后等到好状态一举拿下)
    心得体悟帖---200401(别身在福中不知福,现在是多好的时机,做自己开心的事情)
    心得体悟帖---200401(你做任何事情,抉择和责任都在自己,而不是在别人)
    laravel疑难问题---4、phpstorm中如何配置phpunit(单元测试)
    phpstorm常用配置和快捷键
    phpstorm常用操作---5、phpstorm配置命令行环境
    phpstorm常用操作---4、phpstorm配置phpunit环境
    phpstorm常用操作---3、phpstorm修改默认快捷键
    phpstorm常用操作---2、phpstorm特别常用快捷键
  • 原文地址:https://www.cnblogs.com/acvc/p/3661079.html
Copyright © 2011-2022 走看看