POJ 3258 River Hopscotch (二分法)
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 toM rocks (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
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
Sample Input
25 5 2
2
14
11
21
17
Sample Output
4
Hint
#include<cstdio>
#include<algorithm>
using namespace std;
int l,m,n,a[+],i,le,ri,ans;
int f(int x,int y, int m)
{
while(x<=y)
{
int mid = x+(y-x)/;
int key=,num=;
for(i = ; i <= n+ ; i++)
{
if((num+=a[i]-a[i-])<= mid)
{
key++;
}
else
{
num=;
}
}
if(key <= m)
{
x=mid+;
}
else
{
y=mid-;
}
}
return x;
}
int main()
{
while(scanf("%d %d %d",&l,&n,&m)!=EOF)
{
le=;
ri=l;
a[]=;
a[n+]=l;
for(i = ; i <= n ; i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n+);
for(i=;i<=n+;i++)
{
le=min(le,a[i]-a[i-]);
}
ans=f(le,ri,m);
printf("%d\n",ans);
}
}
POJ 3258 River Hopscotch (二分法)的更多相关文章
- POJ 3258 River Hopscotch(二分法搜索)
Description Every year the cows hold an event featuring a peculiar version of hopscotch that involve ...
- 二分搜索 POJ 3258 River Hopscotch
题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...
- POJ 3258 River Hopscotch
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11031 Accepted: 4737 ...
- POJ 3258 River Hopscotch (binarysearch)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5193 Accepted: 2260 Descr ...
- POJ 3258 River Hopscotch(二分答案)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6697 Accepted: 2893 D ...
- poj 3258 River Hopscotch 题解
[题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...
- poj 3258 River Hopscotch(二分+贪心)
题目:http://poj.org/problem?id=3258 题意: 一条河长度为 L,河的起点(Start)和终点(End)分别有2块石头,S到E的距离就是L. 河中有n块石头,每块石头到S都 ...
- POJ 3258 River Hopscotch 二分枚举
题目:http://poj.org/problem?id=3258 又A一道,睡觉去了.. #include <stdio.h> #include <algorithm> ]; ...
随机推荐
- Linux下备份MySQL数据库的Shell脚本
数据库每天都想备份,手动备份太麻烦而又容易忘记,所以写了一个自动备份MySQL数据库的脚本,加入定时计划中,每天自运运行. 创建Shell脚本代码如下,命名为mysql_dump.sh #!/bin/ ...
- 2018 ACM-ICPC亚洲区域赛(青岛)
Problem C---zoj 4060 Flippy Sequence 解题思路:要求进行两次操作,每次操作选择一个区间,问将s串变成t串中所选的两个区间构成的4元组有多少个.做法:找出s串与t串不 ...
- C# 对象复制
/// <summary> /// 把DataTable对象转成List<T>对象 /// </summary> /// <typeparam name=&q ...
- HAL之EXIT
在STM32cubeMX中 1 在GPIO管脚上选定EXIT功能 2 在GPIO模式中设定触发边沿类型 3 在NVIC中设定NVIC分组及使能EIXT_Line0_interrupt 在MDK中的GP ...
- Spark MLlib编程API入门系列之特征提取之主成分分析(PCA)
不多说,直接上干货! 主成分分析(Principal Component Analysis,PCA), 将多个变量通过线性变换以选出较少个数重要变量的一种多元统计分析方法. 参考 http://blo ...
- vs直接IP访问运行项目
找到IIS Express 正在运行的项目应用程序,点击网站,会出现配置路径,找到配置路径,显示隐藏的文件夹 localhost替换成本地IP,重新运行项目,然后就可以直接通过IP访问项目,好处就是便 ...
- .net 音频转换 .amr 转 .mp3 (ffmpeg转换法)
最近看来是跟声音干上了啊! 音频转换的第二种方法,这种方法相对第一种来说,要简单的多! 首先,你得下载个“ffmpeg.exe” 插件,然后把它放到你的项目中,如下图: 程序中会调用该文件,以助于转换 ...
- LOJ#121. 「离线可过」动态图连通性(线段树分治)
题意 板子题,题意很清楚吧.. Sol 很显然可以直接上LCT.. 但是这题允许离线,于是就有了一个非常巧妙的离线的做法,好像叫什么线段树分治?? 此题中每条边出现的位置都可以看做是一段区间. 我们用 ...
- filter和map的使用
if ( this.dataAggridvue.filter( item => item.Accepted == true && item.InvoiceGroupCode != ...
- Handler引起的内存泄露
一般我都写handler的时候是这样的: public class MyActivity extends Activity{ private final Handler myHandler = n ...