描述


http://poj.org/problem?id=3258

给出起点和终点之间的距离L,中间有n个石子,给出第i个石子与起点之间的距离d[i],现在要去掉m个石子(不包括起终点),求距离最近的两个石子(包括起终点)之间距离的最大值.

River Hopscotch
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 10841   Accepted: 4654

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 M rocks (0 ≤ MN).

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: L, N, 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).

Source

分析


二分.

同 POJ 2456 , 但有一点不同:start与end位置是已经确定好的,只需要在中间n个石子中确定n-m个即可.第一个石子与a[0]即start位置比较,结束之后还要再比较a[n+1]-a[last]>=x是否成立.(也是注意点1)

 #include<cstdio>
#include<algorithm>
using std :: sort; const int maxn=;
int n,l,m;
int a[maxn]; void init()
{
scanf("%d%d%d",&l,&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
sort(a+,a+n+);
a[n+]=l;
} bool C(int x)
{
int last=;
for(int i=;i<=n-m;i++)
{
int now=last+;
while(now<=n&&(a[now]-a[last])<x) now++;
if(now>n) return false;
last=now;
}
if(a[n+]-a[last]<x) return false;
return true;
} int bsearch(int x,int y)
{
while(x<y)
{
int m=x+(y-x+)/;
if(C(m)) x=m;
else y=m-;
}
return x;
} void solve()
{
int INF=l/(n+-m);//共n+1-m个线段,最短的线段最多是l/(n+1-m)
int ans=bsearch(,INF);
printf("%d\n",ans);
} int main()
{
freopen("river.in","r",stdin);
freopen("river.out","w",stdout);
init();
solve();
fclose(stdin);
fclose(stdout);
return ;
}

注意:

1.如上所述.

2.输入数据是无序的,需先用快排进行排序.

POJ_3258_River_Hopscotch_[NOIP2015]_(二分,最大化最小值)的更多相关文章

  1. POJ_2456_Agressive_cows_(二分,最大化最小值)

    描述 http://poj.org/problem?id=2456 有n个小屋,线性排列在不同位置,m头牛,每头牛占据一个小屋,求最近的两头牛之间距离的最大值. Aggressive cows Tim ...

  2. River Hopscotch(二分最大化最小值)

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9923   Accepted: 4252 D ...

  3. POJ3258 River Hopscotch(二分最大化最小值)

    题目链接:http://poj.org/problem?id=3258 题意:给n个石头,起点和终点也是两个石头,去掉这石头中的m个,使得石头间距的最小值最大. 思路:二分石头间的最短距离,每次贪心地 ...

  4. CodeForces 689C Mike and Chocolate Thieves (二分最大化最小值)

    题目并不难,就是比赛的时候没敢去二分,也算是一个告诫,应该敢于思考…… #include<stdio.h> #include<iostream> using namespace ...

  5. poj3104 Drying(二分最大化最小值 好题)

    https://vjudge.net/problem/POJ-3104 一开始思路不对,一直在想怎么贪心,或者套优先队列.. 其实是用二分法.感觉二分法求最值很常用啊,稍微有点思路的二分就是先推出公式 ...

  6. POJ - 2456 Aggressive cows 二分 最大化最小值

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18099   Accepted: 8619 ...

  7. poj3045 Cow Acrobats(二分最大化最小值)

    https://vjudge.net/problem/POJ-3045 读题后提取到一点:例如对最底层的牛来说,它的崩溃风险=所有牛的重量-(底层牛的w+s),则w+s越大,越在底层. 注意范围lb= ...

  8. POJ3285 River Hopscotch(最大化最小值之二分查找)

    POJ3285 River Hopscotch 此题是大白P142页(即POJ2456)的一个变形题,典型的最大化最小值问题. C(x)表示要求的最小距离为X时,此时需要删除的石子.二分枚举X,直到找 ...

  9. poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分

    poj 2456 Aggressive cows && nyoj 疯牛 最大化最小值 二分 题目链接: nyoj : http://acm.nyist.net/JudgeOnline/ ...

随机推荐

  1. javaee学习-新建servlet 直接返回html

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExcepti ...

  2. STL标准模板库 向量容器(vector)

    向量容器使用动态数组存储.管理对象.因为数组是一个随机访问数据结构,所以可以随机访问向量中的元素.在数组中间或是开始处插入一个元素是费时的,特别是在数组非常大的时候更是如此.然而在数组末端插入元素却很 ...

  3. python isinstance 判断各种类型的小细节

    1. 基本语法 isinstance(object, classinfo) Return true if the object argument is an instance of the class ...

  4. 工厂方法(Factory Pattern)

    工厂方法模式定义:定义了一个创建对象的接口,但由子类决定要实例化的类是哪一个.工厂方法让类把实例化推迟到子类.(注:“决定”不是指模式允许子类本身在运行时做决定,而是指在编写创建者类时,不需要知道实际 ...

  5. 【HeadFirst设计模式】8.模板方法模式

    模板方法 定义: 在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中.模板方法使用得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. 策略模式: 定义一个算法家族,并让这些算法可以互 ...

  6. hdu 5014 Number Sequence

    为了a异或b的和最大,只需另b在不大于n的情况下按位取反即可. 这里有两个输出小技巧可以参考: 1.在用printf输出__int64时,在windows下使用格式"%I64d", ...

  7. Sublime Text 3插件安装方法

    安装Sublime Tex 3t插件的方法: 按快捷键Ctrl + ~ 调出console 粘贴以下代码到console并回车: import urllib.request,os; pf = 'Pac ...

  8. ACE_linux:读写锁

    1.涉及类 ACE_RW_Thread_Mutex //ACE读写锁ACE_Read_Guard //ACE加读锁ACE_Write_Guard //ACE加写锁ACE_Thread_Manager ...

  9. CSS中Padding的用法

    Padding的英文意思是填充,在CSS中则是设置内边距属性. padding不允许使用负值 1. 四个参数时: padding: 10px,20px,30px,40px; 上边距:10px 右边距: ...

  10. hdu 5654 xiaoxin and his watermelon candy 树状数组维护区间唯一元组

    题目链接 题意:序列长度为n(1<= n <= 200,000)的序列,有Q(<=200,000)次区间查询,问区间[l,r]中有多少个不同的连续递增的三元组. 思路:连续三元组-& ...