POJ3258-River Hopscotch-二分

时间:2021-10-07 09:28:59

这个题就是排排坐,二分就可以了。。。

River Hopscotch

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 13253   Accepted: 5652

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).
 
 
代码:
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
int a[];
int l,n,m,i;
int maxx,minn,mid,cnt,sum;
while(~scanf("%d%d%d",&l,&n,&m)){
a[]=;a[n+]=l;
for(i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a,a+n+);
maxx=l;
minn=;
for(i=;i<=n+;i++)
minn=min(minn,a[i]-a[i-]);
while(minn<=maxx){
mid=(minn+maxx)>>;
cnt=sum=;
for(i=;i<=n+;i++){
if((sum+=a[i]-a[i-])<=mid)
cnt++;
else
sum=;
}
if(cnt<=m)
minn=mid+;
else
maxx=mid-;
}
printf("%d\n",minn);
}
return ;
}
//总算知道自己哪里错了。。。n应该+1的。

POJ3258-River Hopscotch-二分的更多相关文章

  1. POJ3258 River Hopscotch —— 二分

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

  2. River Hopscotch&lpar;二分POJ3258&rpar;

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

  3. POJ--3258 River Hopscotch &lpar;最小值最大化C&plus;&plus;&rpar;

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15273   Accepted: 6465 ...

  4. POJ 3258 River Hopscotch&lpar;二分答案&rpar;

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

  5. POJ3258 River Hopscotch 2017-05-11 17&colon;58 36人阅读 评论&lpar;0&rpar; 收藏

    River Hopscotch Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13598   Accepted: 5791 ...

  6. &lbrack;ACM&rsqb; POJ 3258 River Hopscotch &lpar;二分,最大化最小值)

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

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

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

  8. poj3258 River Hopscotch(二分最小值,好题)

    https://vjudge.net/problem/POJ-3258 二分最小值,判断需要删去的点的个数,如果大于给定,则直接return 0,则说明该数需要再小. 最后注意,起点是0终点是l,起点 ...

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

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

  10. G - River Hopscotch&lpar;二分&rpar;

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

随机推荐

  1. Leetcode 60&period; Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  2. IOS之Foundation--plist简说

    将集合元素通过代码写入plist文件中 主要用来一览代码写入plist文件,在以后的工作中,可能会有字典一样的集合元素,需要你转为plist文件,那么你是选择手动输入plist文件中呢,还是通过以下代 ...

  3. YTU 2991&colon; 链表节点逆置(线性表)

    2991: 链表节点逆置(线性表) 时间限制: 1 Sec  内存限制: 128 MB 提交: 14  解决: 6 题目描述 设计一个算法,将一个带头节点的数据域依次为a1,a2,-,an(n> ...

  4. commondline 之二 执行类

    E:\cn\zno\commandline\Test.class package cn.zno.commandline; import java.lang.management.ManagementF ...

  5. Hadoop2&period;0&sol;YARN深入浅出&lpar;Hadoop2&period;0、Spark、Storm和Tez&rpar;

    随着云计算.大数据迅速发展,亟需用hadoop解决大数据量高并发访问的瓶颈.谷歌.淘宝.百度.京东等底层都应用hadoop.越来越多的企 业急需引入hadoop技术人才.由于掌握Hadoop技术的开发 ...

  6. awk 用法小结

    简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再 ...

  7. python读取并写入csv文件

    在ubuntu下,新建.csv文件的方法是使用LibreOffice来创建一个数据表,然后我们把表格存储为.csv的格式: “Save as”菜单把我们的表格存为一个CSV的文件格式:命名为csvDa ...

  8. git命令及远程仓库操作内容整理

    0.在git官网上下载git对应的适配系统版本 进入到需要管理的目录,打开git终端 1.git相关的基础命令: git init 在当前文件夹下创建一个.git的隐藏文件夹,初始化版本控制器 注:不 ...

  9. Vector 是线程安全的,是不是在多线程下操作Vector就可以不用加Synchronized

    如标题一样,如果之前让我回答,我会说,是的,在多线程的环境下操作Vector,不需要加Synchronized. 但是我今天无意间看到一篇文章,我才发现我之前的想法是错误的,这篇文章的地址: http ...

  10. 不能用c99的情况下,如何动态定义数组的长度

    #include <stdio.h>#include <stdlib.h> int main(int argc, char const *argv[]){    int num ...