zoukankan      html  css  js  c++  java
  • POJ 3258 River Hopscotch

    Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    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 torocks (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

    Hint

    Before removing any rocks, the shortest jump was a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and 14, the shortest required jump is a jump of 4 (from 17 to 21 or from 21 to 25).
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <algorithm>
     4 using namespace std;
     5 
     6 const int INF=1e9+7;
     7 
     8 int l,n,m;
     9 int a[50005],mi;
    10 
    11 bool C(int x)
    12 {
    13     if(x>l)
    14         return false;
    15     int num=0,i,j,nu=0;
    16     for(i=1;i<=n;i++)
    17     {
    18         if(a[i]-nu<x)
    19             num++;
    20         else
    21             nu=a[i];
    22     }
    23     return num<=m;
    24 }
    25 
    26 int main()
    27 {
    28     while(scanf("%d %d %d",&l,&n,&m)!=EOF)
    29     {
    30         for(int i=1;i<=n;i++)
    31         {
    32             scanf("%d",&a[i]);
    33         }
    34         sort(a+1,a+n+1);
    35 
    36         mi=a[1];
    37         for(int i=2;i<=n;i++)
    38             if(a[i]-a[i-1]<mi)
    39                 mi=a[i]-a[i-1];
    40 
    41         a[n+1]=l;a[0]=0;
    42         n++;
    43 
    44         int lb=0,ub=INF;
    45         for(int i=1;i<=100;i++)
    46         {
    47             int mid=(lb+ub)/2;
    48             if(C(mid))
    49                 lb=mid;
    50             else
    51                 ub=mid;
    52         }
    53         printf("%d
    ",lb);
    54     }
    55     return 0;
    56 }
    View Code
  • 相关阅读:
    异常问题处理记录(转载篇)
    linux服务器出现大量连接:sshd: root@notty
    第4章 Python运算符
    第2章 python基础知识
    第1章 python环境搭建
    Tomcat漏洞升级
    第3章 数据类型、运算符和表达式
    第2章 C语言基础知识
    第1章 概述
    第1章 企业管理概论
  • 原文地址:https://www.cnblogs.com/cyd308/p/4693655.html
Copyright © 2011-2022 走看看