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块石头之后似的石头之间的最短距离最大. 这道题目感觉大致代码写起来不算困难,难点在于边界处理上.我思考边界思 ...
随机推荐
- DeprecationWarning:'open()' is deprecated in mongoose>=4.11.0,use 'openUri()' instead or set the 'useMongoClient' option if using 'connect()' or 'createConnection'
mongoose.connect('mongodb://localhost/test');报错:(node:2752) DeprecationWarning: `open()` is deprecat ...
- 使用 Doxygen 生成文档 (以FFmpeg 4.1.1 为例)
背景 在查找 ffmpeg 文档的时候,发现其文档是根据 Doxygen 生成的. 为了学习方便,这里以 生成 ffmpeg 4.1 文档 为例. 注:为了兼顾 arm 与 host ,本人选择了同时 ...
- 智能充电安全管理首选SOC单芯片方案:SI24R2F
SI24R2F简介: SI24R2F是一颗工作在2.45GHZ ISM 频段,专为低功耗有源RFID应用场合设计,集成崁入式2.45GHZ 无线射频发射器模块.64次可编程NVM存储器模块 ...
- vue 加载静态图片
<img class="headImg" :src="require('../../assets/uploads/'+headImg)" alt=&quo ...
- 7.9 规划Varnish缓存
./varnishlog -i VCL_LOG
- SQL计算字符串里的子字符串出现个数
在某个页面,需要显示每条记录中有几个图片文件.图片文件名列表存储在mysql表里的photo_files字段,文件名之间用一个空格分开.类似'images\rpt201503121.jpg image ...
- System.Data.SqlClient.SqlException: 'Incorrect syntax near 'OFFSET'.
https://www.nopcommerce.com/boards/t/54586/410-not-running-on-local-system.aspx#209684 Hello, I was ...
- Windows安装tensorflow,配置vs2013,anaconda3.4,cudn9.0,cudnn7.0和pycharm
前言 最近要开始学习深度,那么首先在电脑上安装tensorflow.但是我不知道是配置版本的问题,还是安装失误的问题,我安装了很久没有安装成功,最后重装了电脑,并且融合了所有的网上可以查到的方案才安装 ...
- C#常用类库简介(二)
原文出处:http://blog.csdn.net/weiwenhp/article/details/8140503 C#常用类库简介(一)的地址 System与mscorlib这两个dll中的类库是 ...
- cf 500 D. New Year Santa Network
直接按边分,2个点在边的一边,1个在另一边,组合出来就是这个边对答案的贡献,权值换了就再重新算个数而已. #include <bits/stdc++.h> #define LL long ...