zoukankan      html  css  js  c++  java
  • River Hopscotch(二分)

    Time Limit: 2000MS   Memory Limit: 65536K
    Total Submissions: 5473   Accepted: 2379

    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 Mrocks (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 ofM 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

    输入L,N,M;L表示终点离起点的距离,从起点到终点有N块石头(不包含起点和终点),要求移除M块石头后,使得那时的最短距离尽可能的大,并输出这个距离;
    类似于poj3273;

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<algorithm>
     4 using namespace std;
     5 
     6 const int N = 50000;
     7 int l,n,m;
     8 int rock[N+10];
     9 int low,high,mid;
    10 
    11 bool judge(int mid)
    12 {
    13     int sum = 0;
    14     int group = 0;
    15     for(int i = 1; i <= n+1; i++)
    16     {
    17         if(sum + (rock[i]-rock[i-1]) <= mid)
    18         {
    19             sum += rock[i]-rock[i-1];
    20             group++;
    21         }
    22         else
    23         {
    24             sum = 0;
    25         }
    26     }
    27     if(group > m)
    28         return false;
    29     return true;
    30 }
    31 
    32 int main()
    33 {
    34     scanf("%d %d %d",&l,&n,&m);
    35     rock[0] = 0;
    36     rock[n+1] = l;
    37     low = l;
    38     high = l;
    39     for(int i = 1; i <= n+1; i++)
    40     {
    41         if(i <= n)
    42             scanf("%d",&rock[i]);
    43         if(low > rock[i]-rock[i-1])
    44             low = rock[i]-rock[i-1];
    45     }
    46     sort(rock,rock+(n+2));
    47 
    48 
    49     while(low <= high)
    50     {
    51         mid = (low+high)/2;
    52         if(!judge(mid))
    53             high = mid-1;
    54         else low = mid+1;
    55     }
    56     printf("%d
    ",low);
    57     return 0;
    58 }
    View Code

  • 相关阅读:
    VM启用ISO共享
    部署服务--NLB
    SCVMM问题汇总
    判断文件是否存在(exist)
    函数(Function)作用域 / 远程函数执行
    基于433MHz无线串口,多发一收解决方案
    ZigBee自组网地址分配与路由协议概述
    Zigbee协议栈--Z-Stack的使用
    RT-Thread RTOS
    信息量、互斥信息量和事件标志
  • 原文地址:https://www.cnblogs.com/LK1994/p/3364180.html
Copyright © 2011-2022 走看看