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 ...
随机推荐
- Java设计原则之里氏替换原则
里氏代换原则由2008年图灵奖得主.美国第一位计算机科学女博士Barbara Liskov教授和卡内基·梅隆大学Jeannette Wing教授于1994年提出.其严格表述如下:如果对每一个类型为S的 ...
- 杂项:CDN
ylbtech-杂项:CDN CDN的全称是Content Delivery Network,即内容分发网络.其基本思路是尽可能避开互联网上有可能影响数据传输速度和稳定性的瓶颈和环节,使内容传输的更快 ...
- JedisCluster中应用的Apache Commons Pool对象池技术
对象池技术在服务器开发上应用广泛.在各种对象池的实现中,尤其以数据库的连接池最为明显,可以说是每个服务器必须实现的部分. apache common pool 官方文档可以参考:https://c ...
- 【C++11新特性】 - 空间配置allocator类
原文链接: http://blog.csdn.net/Xiejingfa/article/details/50955295 今天我们来讲讲C++的allocator类. C++提供了new和delet ...
- 软件测试——Peer Review(简介)
1. 同行评审的种类和对象 同行评审活动的关注点应该是工作产品中的缺陷,而不应该是工作产品的作者或者生产者,管理者也不应使用同行评审的结果去评价个人的行为. 同行评审的分类有很多种,自从IBM的Fag ...
- oracle创建表空间,表及用户
oracle要创建表要首先创建表空间,当然默认是有表空间的.而mysql创建表时,会自动创建表空间,myisam会自动建三个文 件.MYD,.MYI,.frm.innodb呢,如果没有配置独立表空间的 ...
- python编程之禅
在python界面输入 import this >>> import this The Zen of Python, by Tim Peters Beautiful is bette ...
- 0_Simple__UnifiedMemoryStreams
使用 OpenMP 和 pthreads 两种环境,利用实现统一内存编址,计算基本的矩阵乘法 result = α * A * x + β * result . ▶ 源代码 #include < ...
- 0_Simple__simpleP2P
使用 P2P 特性在 GPU 之间传输.读写数据. ▶ 源代码.包括 P2P 使用前的各项检查,设备之间的数据互拷,主机和设备之间数据传输和相互访问. #include <stdlib.h> ...
- openlayers-热地图加载(完整版及代码)
//地圖加載function mapInit(data){ //底图// var raster = new ol.layer.Tile({// source: new ol.source.Stamen ...