774. Minimize Max Distance to Gas Station

On a horizontal number line, we have gas stations at positions stations[0], stations[1], ..., stations[N-1], where N = stations.length.
Now, we add K more gas stations so that D, the maximum distance between adjacent gas stations, is minimized.
Return the smallest possible value of D.
Example:
Input: stations = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], K = 9
Output: 0.500000




On a horizontal number line, we have gas stations at positions stations[0], stations[1], ..., stations[N-1], where N = stations.length.
    
    
    N- 1 = 10 , N = 11 = stations.length 
    
    K = 9
    add another 9 stations , the maximum distance between adjacent gas station is minimized 
    return the Return the smallest possible value of D.
    
    0  x 1, x  2,x 3,x 4,x 5,x 6,x 7,x 8, x 9, x 10 x  11
    so right now, the max distance between two adjacent cells is 0.5 
    
https://leetcode.com/problems/minimize-max-distance-to-gas-station/discuss/113629/Approach-the-problem-using-the-%22trial-and-error%22-algorithm




https://leetcode.com/problems/minimize-max-distance-to-gas-station/solution/


Binary search 


参考discuss,假设一个结果,然后对结果进行二分逼近。

 

posted on 2018-11-09 06:40  猪猪🐷  阅读(107)  评论(0)    收藏  举报

导航