River Hopscotch
River Hopscotch
http://poj.org/problem?id=3258
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 21165 | Accepted: 8791 |
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 ≤ 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 Mrocks.
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
Source
mid设为最短跳跃距离的最大值
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std; int a[];
int L,N,M; bool erfen(int mid){
int sum=;
int tmp=a[];
int i=;
while(i<=N+){
if(a[i]-tmp<mid){
i++;
sum++;
}
else{
tmp=a[i++];
}
}
if(sum>M) return false;
return true;
} int main(){ cin>>L>>N>>M;
for(int i=;i<=N;i++){
cin>>a[i];
}
sort(a+,a+N+);
a[]=,a[N+]=L;
int LL=,RR=L,mid;
while(LL<=RR){
mid=LL+RR>>;
if(erfen(mid)){
LL=mid+;
}
else{
RR=mid-;
}
}
cout<<RR<<endl;
system("pause");
}
River Hopscotch的更多相关文章
- POJ 3258 River Hopscotch
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11031 Accepted: 4737 ...
- River Hopscotch(二分POJ3258)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9263 Accepted: 3994 Descr ...
- POJ 3258 River Hopscotch (binarysearch)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5193 Accepted: 2260 Descr ...
- POJ3285 River Hopscotch(最大化最小值之二分查找)
POJ3285 River Hopscotch 此题是大白P142页(即POJ2456)的一个变形题,典型的最大化最小值问题. C(x)表示要求的最小距离为X时,此时需要删除的石子.二分枚举X,直到找 ...
- River Hopscotch(二分最大化最小值)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9923 Accepted: 4252 D ...
- POJ--3258 River Hopscotch (最小值最大化C++)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15273 Accepted: 6465 ...
- POJ 3258 River Hopscotch(二分答案)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21939 Accepted: 9081 Desc ...
- bzoj1650 / P2855 [USACO06DEC]河跳房子River Hopscotch / P2678 (noip2015)跳石头
P2855 [USACO06DEC]河跳房子River Hopscotch 二分+贪心 每次二分最小长度,蓝后检查需要去掉的石子数是否超过限制. #include<iostream> #i ...
- POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13598 Accepted: 5791 ...
随机推荐
- OS信号实现Java异步通知
OS信号实现Java异步通知本文将结合操作系统的信号机制,来尝试实现一个简单的,不依赖功能环境的Java异步通知功能.没有特殊说明,本文所有的示例,都是基于Linux.信号简介信号是在软件层次上对中断 ...
- 操作系统-移动操作系统-百科: iOS(苹果公司的移动操作系统)
ylbtech-操作系统-移动操作系统-百科: iOS(苹果公司的移动操作系统) iOS是由苹果公司开发的移动操作系统.苹果公司最早于2007年1月9日的Macworld大会上公布这个系统,最初是设计 ...
- Jquery判断IE6等浏览器的代码
这好像是由几篇代码接在一起的,原文均来自网络,不记得出处了~ jquery中利用navigator.userAgent.indexOf来判断浏览器类型,并进行了一下处理,如果不想使用jquery,稍为 ...
- zabbix批量添加SNMP监听H3C端口检测以及流量图
由于之前网络设备不是很多,监控网络设备接口就直接使用模版中的item来实现了,可是现在公司上线了一大批网络设备,如果要每个网络设备都做模板,添加item......那就该废了,于是迫于压力今天来测试使 ...
- Unity的JIT和AOT实现
https://myhloli.com/about-il2cpp.html JIT方式: Unity的跨平台技术是通过一个Mono虚拟机实现的.而这个虚拟机更新太慢,不能很好地适应众多的平台. And ...
- BI开发(ETL-DW)
来到公司已经参与开发了一段时间的BI项目,但是仅仅是按照需求开发,今天下午公司给大家培训数据仓库的知识,老大(女程序员)在上面讲,我们在下面听,2到3个小时吧,什么纬度,主题,几乎听的一脸茫然,最后演 ...
- Java面向对象技术
问题及答案来源自<Java程序员面试笔试宝典>第四章 Java基础知识 4.2面向对象技术 1.面向对象与面向过程有什么区别? 看下面一个实例即可: 面向过程就是分析出解决问题所需要的步骤 ...
- QT按键(Qbutton)改变颜色
第一种是按键上面的字颜色的改变: ui->motor1->setStyleSheet("color: red"); 效果: 第二种是背景改变: ui->mot ...
- aspxGridview 根据单元格值得不同,设置单元格字体的颜色(设置和读取值)
protected void ASPxGridView1_HtmlRowCreated(object sender,DevExpress.Web.ASPxGridView.ASPxGridViewTa ...
- 1.JSONObject与JSONArray的使用
参考文献: http://blog.csdn.net/huangwuyi/article/details/5412500 1.JAR包简介 要使程序可以运行必须引入JSON-lib包,JSON-lib ...