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 ...
随机推荐
- ASP.NET Web Pages:Chart 帮助器
ylbtech-.Net-ASP.NET Web Pages:Chart 帮助器 1.返回顶部 1. ASP.NET Web Pages - Chart 帮助器 Chart 帮助器 - 众多有用的 A ...
- SIP 认证方式
SIP认证是继承了HTTP的认证方式.HTTP的认证方案主要有Basic Authentication Scheme和Digest Access Authentication Scheme两种.而Ba ...
- Oracle创建数据库链接
**********创建数据库链接******************create public database link link_gzzl connect to system identifie ...
- HTML5中对于网络是否断开的检测.很有意思哦
//事件的封装 var EventUtil = { addHandler: function (element, type, handler) {//注册事件 if (element.addEvent ...
- javascript的面向对象思想知识要点
获取数据类型 typeof undefined:访问某个不存在的或未经赋值的变量时就会得到一个 undefined,用typeof 获取类型,得到的也是undefined;null:它不能通过java ...
- 小朋友学C++(1)
Hello World! 在学C++之前,最好先学习一下C语言 让我们先运行一段简单的代码,编译器可以使用 在线C++编译器 或 Xcode(苹果系统) 或Dev C++(Windows系统). #i ...
- ORM( ORM查询13种方法3. 单表的双下划线的使用 4. 外键的方法 5. 多对多的方法 ,聚合,分组,F查询,Q查询,事务 )
必知必会13条 <1> all(): 查询所有结果 <2> get(**kwargs): 返回与所给筛选条件相匹配的对象,返回结果有且只有一个,如果符合筛选条件的对象超过一个或 ...
- mybatis Dynamic SQL动态 SQL
动态 SQL MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其它类似框架的经验,你就能体会到根据不同条件拼接 SQL 语句的痛苦.例如拼接时要确保不能忘记添加必要的空格 ...
- 使用Larave5.6l提交POST请求出现The page has expired due to inactivity错误
使用Larave5.6l提交POST请求出现The page has expired due to inactivity错误 一般是由于没有添加 csrf造成的 在表单下面的 第一个行 添加如下代码即 ...
- 代码:cookie(一个广告展示例子)
这个小例子的要求是: 用户第一次进入,显示大图,2秒后大图动画关闭,再把小图动画展开: 用户再次进入后,只显示静态小图. 做法: 定义一个容器 .img201512ad,宽高写死:1190x70.—— ...