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;
 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int N = ;
int l,n,m;
int rock[N+];
int low,high,mid; bool judge(int mid)
{
int sum = ;
int group = ;
for(int i = ; i <= n+; i++)
{
if(sum + (rock[i]-rock[i-]) <= mid)
{
sum += rock[i]-rock[i-];
group++;
}
else
{
sum = ;
}
}
if(group > m)
return false;
return true;
} int main()
{
scanf("%d %d %d",&l,&n,&m);
rock[] = ;
rock[n+] = l;
low = l;
high = l;
for(int i = ; i <= n+; i++)
{
if(i <= n)
scanf("%d",&rock[i]);
if(low > rock[i]-rock[i-])
low = rock[i]-rock[i-];
}
sort(rock,rock+(n+)); while(low <= high)
{
mid = (low+high)/;
if(!judge(mid))
high = mid-;
else low = mid+;
}
printf("%d\n",low);
return ;
}

River Hopscotch(二分)的更多相关文章

  1. River Hopscotch(二分POJ3258)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9263 Accepted: 3994 Descr ...

  2. POJ 3258 River Hopscotch(二分答案)

    River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...

  3. [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6697   Accepted: 2893 D ...

  4. POJ3258 River Hopscotch —— 二分

    题目链接:http://poj.org/problem?id=3258 River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total ...

  5. POJ 3258:River Hopscotch 二分的好想法

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9326   Accepted: 4016 D ...

  6. G - River Hopscotch(二分)

    Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully ...

  7. poj 3258 River Hopscotch(二分+贪心)

    题目:http://poj.org/problem?id=3258 题意: 一条河长度为 L,河的起点(Start)和终点(End)分别有2块石头,S到E的距离就是L. 河中有n块石头,每块石头到S都 ...

  8. poj 3258 River Hopscotch 二分

    /** 大意:给定n个点,删除其中的m个点,其中两点之间距离最小的最大值 思路: 二分最小值的最大值---〉t,若有距离小于t,则可以将前面的节点删除:若节点大于t,则继续往下查看 若删除的节点大于m ...

  9. POJ 3258 River Hopscotch 二分枚举

    题目:http://poj.org/problem?id=3258 又A一道,睡觉去了.. #include <stdio.h> #include <algorithm> ]; ...

随机推荐

  1. spring beans源码解读之--BeanFactory的注册

    beanFactory的继承关系如下图所示: (图片来源:http://www.myexception.cn/software-architecture-design/925888.html) 在上节 ...

  2. 一个Web Project引用多个Java Project在Eclipse下的配置--转载

    项目结构: 项目由一个Web Project和多个Java Project构成,Web Project需要引用其它Java Project的类和Jar包.开发时用Eclipse3.5和Tomcat调试 ...

  3. mysql查看端口

    在你的my.ini(Windows)或my.cfg(Linux) 中就有啊. 或者如果已经连入MySQL可以直接 SQL code ? 1 2 3 4 5 6 7 8 9 mysql> show ...

  4. c# 的导入功能SqlBulkCopy

    private static void DataTableToSQLServer( DataTable dt) { string connectionString = GetConnectionStr ...

  5. ASP.NET Webform或者ASP.NET MVC站点部署到IIS下,默认情况下.json文件是不能被访问的,如果请求访问.json文件,则会出现找不到文件的404错误提示

    解决方法 <system.webServer> <staticContent> <remove fileExtension=".woff" /> ...

  6. 15、SQL Server 触发器

    SQL Server 触发器 触发器是一种特殊的存储过程,只有当试图用数据操作语言DML来修改数据时才会触发,DML包含对视图和表的增.删.改. 触发器分为DML触发器和DDL触发器,其中DML触发器 ...

  7. discuz论坛几种安全策略(二)

    大头看了我给的方案,http://www.cnblogs.com/itsmylife/p/4012000.html 今早给的回复如下: “ 补充几点,供参考: 第一条,配置一下允许上传文件的格式以及大 ...

  8. OpenWrt的主Makefile工作过程

    OpenWrt是一个典型的嵌入式Linux工程,了解OpenWrt的Makefile的工作过程对提高嵌入式Linux工程的开发能力有极其重要意义. OpenWrt的主Makefile文件只有100行, ...

  9. sql yog注册码

    Name: AnyRegistration Code: 26f359fc-e3f6-4727-8af1-72a1a4a0819d

  10. ajax使用中发现的问题与深入扩展(for循环中嵌套ajax)

    在学习ajax的过程中,我曾经遇到过这样的一个问题,为了得到一个详情列表,我要先向服务器去请求得到索引表,简单描述就是ajax中的success中的for循环中再次嵌套了ajax,结果第二层succe ...