POJ-3258 (最小值最大化问题)
POJ - 3258
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 Line 1: Three space-separated integers: L, N, and M
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 Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks
Sample Input 25 5 2 Sample Output 4 Hint Before removing any rocks, the shortest jump was a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and 14, the shortest required jump is a jump of 4 (from 17 to 21 or from 21 to 25).
Source 今天被这个题目坑了好久。。。顺便发现,自己其实还是没能真正完全将分治思想融会贯通。。。坑了好久啊。。
发现自己离ACM真正的神路,还有好远好远。。。一个算法学过虽然能A题了,但其实还没理解清楚其中的原理,只是记住了模板,换一个题目就不行了
就像这道最小值最大化。。。跟之前的最大值最小化完全是兄弟题,做法也相当类似,都是二分,,,只不过,这个题目的二分 要怎么个分法,就跟之前有很大的不同了
这也是坑了我好久的地方,所以,发现,自己着实基本功不够,。。二分是知道怎么做,但是具体怎么分的,就千差万别了。。。感觉还是没理清题目思路,之前还好
做着做着人就笨了。。还看别人的博客,影响了自己的思维。
好吧。。先这样说,具体再解系这个题目的二分方法。。。等明天吧。。貌似还有1分钟就0点了。。。明天再说吧。。晚安,先去睡了
这个题目的思路是这样的:
1.首先必须要排序,这个是肯定的。而且最好在排完序之后得到此时对应的每两个石头的间距记录下来。
2.确立二分的上下界,上界肯定就是河流的宽度嘛,下界就是最小石头间距。
3.然后就是典型的二分法了,在上下界之间二分,难些的是判断条件,其实理清了思路倒也不难。
4.判断当前mid值得方法是这样的,循环所有的石头间距,逐个累加,如果没有超过当前mid,意味着该石头可以搬开,即搬石头数++,如果超过了当前mid,则不能搬了,而且要把此时的累加距清零,以便后一段继续这样的事
5.根据循环之后的结果,如果搬石头数目超过了规定的m,说明mid值过大。。于是上界缩小。。。如果小于,则下界增大。。。由此二分完毕即得最大化间距。
贴的是小优大神的代码
//Memory Time |
POJ-3258 (最小值最大化问题)的更多相关文章
- POJ 3258 最小值最大化 二分搜索
题意:牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值. ...
- poj 3258 3273
poj3258 题目 (最大化最小值)(最小值最大化) 题意:牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离,现在去掉M块石头,要求去掉M块石 ...
- poj 3258 River Hopscotch 题解
[题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...
- POJ--3258 River Hopscotch (最小值最大化C++)
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15273 Accepted: 6465 ...
- Halum UVA - 11478(差分约束 + 二分最小值最大化)
题意: 给定一个有向图,每条边都有一个权值,每次你可以选择一个结点v和一个整数d,把所有以v为终点的边的权值减小d,把所有以v为起点的边的权值增加d,最后要让所有边权的最小值非负且尽量大 两个特判 1 ...
- Now or later UVALive - 3211(2-SAT 最小值最大化)
emmm...去吃早饭了... rujia讲的很好.. 最小值最大化问题,,,二分枚举答案 设x1.x2为同一个集合中的元素,y1.y2为另一个集合中的元素,如果x1与y1之差小于mid,那么如果 ...
- 二分搜索 POJ 3258 River Hopscotch
题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...
- E - River Hopscotch POJ - 3258(二分)
E - River Hopscotch POJ - 3258 Every year the cows hold an event featuring a peculiar version of hop ...
- POJ 3258(二分求最大化最小值)
题目链接:http://poj.org/problem?id=3258 题目大意是求删除哪M块石头之后似的石头之间的最短距离最大. 这道题目感觉大致代码写起来不算困难,难点在于边界处理上.我思考边界思 ...
随机推荐
- NOIP2017tg【逛公园】 题解
先说点别的 emmm--,这是本蒟蒻的第一篇题解,大佬们勿喷QwQ(要不是看到写题解可以加贡献,我才--) 可以看到标签,是2017年提高的题目,好像是Day1T3,感觉提高考这样的题目挺好的,至少考 ...
- sqlserver查找断号,回收单据号
declare @L varchar(20), @R varchar(20), @Len int, @FromNo int, @F1 intselect @L='19011', @R='', @Len ...
- MySQL性能调优语句
mysql>show global status; 可以列出MySQL服务器运行各种状态值 一.慢查询 mysql> show variables like '%slow%'; mysql ...
- Mybatis注解开发单表CRUD
Mybatis注解开发单表CRUD mybatis注解开发和xml开发不可兼容,要么全部使用注解,要么全部使用xml,个人建议注解,简单. 当实体类属性名称和数据库表属性名称一致时:无需配置Resul ...
- java多线程(待完善)
1.小型系统 // 线程完成的任务(Runnable对象)和线程对象(Thread)之间紧密相连 class A implements Runnable{ public void run(){ // ...
- 今日份学习: Spring中使用AOP并实现redis缓存?
笔记 在Spring中如何使用AOP? Spring是如何切换JDK动态代理和CGLIB的? spring.aop.proxy-target-class=true (在下方第二个链接中,原生doc中提 ...
- vue :style 动态绑定style
<div class="right userPicture" :style="[{'background':`url(${userImg}) no-repeat c ...
- VUE - vue.runtime.esm.js?6e6d:619 [Vue warn]: Do not use built-in or reserved HTML elements as component i
<script> export default { name:'header' // 不要使用内置或保留的HTML元素 , 改为Header或者置或保留的HTML元素 ...
- [CodeForces]1263A Sweet Problem
题目链接 题目描述 You have three piles of candies: red, green and blue candies: the first pile contains only ...
- 利用 Ruoyi 开发自己的业务管理系统__测试结构完成
前言铺垫不多说 (1)Ruoyi这个平台不错:如果你觉得你比Ruoyi的作者牛逼,你就不用看我这个文章了,你可以走了,因为我自认为比Ruoyi的作者要烂: (2)必须已经成功搭建Ruoyi,并能在自己 ...