码迷,mamicode.com
首页 > 其他好文 > 详细

HackerRank "Flatland Space Stations"

时间:2016-08-07 15:14:47      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

A bit Greedy can achieve O(m) - the mid station between 2 adjacent cities has the longest distance within that range.

#include <vector>
#include <iostream>
using namespace std;


int main(){
    int n;
    int m;
    cin >> n >> m;
    vector<int> c(m);    
    for(int c_i = 0;c_i < m;c_i++){
       cin >> c[c_i];
    }
    sort(c.begin(), c.end());
    int r = 0;
    for(int i =0; i < m - 1; i ++)
    {
        r = max(r, (c[i + 1] - c[i])/2);
    }
    r = max(r, c[0]);
    r = max(r, n - c.back() - 1);
    cout << r << endl;
    
    return 0;
}

HackerRank "Flatland Space Stations"

标签:

原文地址:http://www.cnblogs.com/tonix/p/5746040.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!