POJ3258-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 ≤ 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<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-二分的更多相关文章
- POJ3258 River Hopscotch —— 二分
题目链接:http://poj.org/problem?id=3258 River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total ...
- River Hopscotch(二分POJ3258)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9263 Accepted: 3994 Descr ...
- 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 ...
- POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13598 Accepted: 5791 ...
- [ACM] POJ 3258 River Hopscotch (二分,最大化最小值)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6697 Accepted: 2893 D ...
- POJ 3258:River Hopscotch 二分的好想法
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9326 Accepted: 4016 D ...
- poj3258 River Hopscotch(二分最小值,好题)
https://vjudge.net/problem/POJ-3258 二分最小值,判断需要删去的点的个数,如果大于给定,则直接return 0,则说明该数需要再小. 最后注意,起点是0终点是l,起点 ...
- POJ3258 River Hopscotch(二分最大化最小值)
题目链接:http://poj.org/problem?id=3258 题意:给n个石头,起点和终点也是两个石头,去掉这石头中的m个,使得石头间距的最小值最大. 思路:二分石头间的最短距离,每次贪心地 ...
- G - River Hopscotch(二分)
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully ...
随机推荐
- go实例之排序
1.默认排序 使用sort包进行排序.排序是就地排序,因此它会更改给定的切片,并且不返回新的切片. package main import "fmt" import "s ...
- IT服务(运维)管理实施的几个要点--序言
IT服务(运维)管理(不是IT运维技术)是IT行业当中相对比较"窄"的一个分支,通常只被金融.电信等大型数据中心的中高层管理人员所关注.但是根据笔者多年从事IT服务和服务管理的经验 ...
- SQL语句 我喜欢上海
select * from [user] wherer name like '上海%'
- websocket教程(一) 非常有趣的理解websocket
一.websocket与http WebSocket是HTML5出的东西(协议),也就是说HTTP协议没有变化,或者说没关系,但HTTP是不支持持久连接的(长连接,循环连接的不算) 首先HTTP有 1 ...
- 连接虚拟机mysql无法访问,报错编号1130的解决方法
新装一台虚拟机mysql的时候,往往会出现win无法连接的情况,报错信息1130,是因为没有权限的问题,解决方案如下: mysql -u root -p mysql>use mysql; mys ...
- Java语言的概述?-什么是Java? (附一张Java工程师的学习路线图)
什么是Java? Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承.指针等概念,因此Java语言具有功能强大和简单易用两个特征.Java语言作为静态面向 ...
- c#实现超实用的<证件照换底色>小工具
1前言 我们在工作和生活中经常要填写一些个人资料,这时候往往需要放证件照上去,但是有时候人家要求是红底或白底,但是偏偏不巧的是你以前照了张蓝底的.这时候你想换个底色,于是在百度上一搜“证件照换 ...
- chrome调试工具高级不完整使用指南(基础篇)
一.前言 本文记录的是作者在工作上面对chrome的一些使用和情况的分析分享,内容仅代表个人的观点.转发请注明出处(http://www.cnblogs.com/st-leslie/),谢谢合作 二. ...
- unittest单元测试框架详解
unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果.今天笔者 ...
- TurnipBit-MicroPython开发板:跟孩子一起DIY跳动的心
天是越来越热了,小心脏也是越跳越快啊,为了表达现在激动的心情,必须做个激动的心开始跳动.紧接着就开始带领大家做个激动的心. 首先说说要借助的平台,这次仅仅需要借助一块TurnipBit开发板. Tur ...