HackerRank "Flatland Space Stations"

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;
}
时间: 2024-11-05 19:02:09

HackerRank "Flatland Space Stations"的相关文章

整体二分-BZOJ2527【poi2011】meteors

2527: [Poi2011]Meteors Time Limit: 60 Sec Memory Limit: 128 MB Submit: 405 Solved: 160 [Submit][Status][Discuss] Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The planet is unsuitable for colo

【BZOJ 2527】 [Poi2011]Meteors

2527: [Poi2011]Meteors Time Limit: 60 Sec Memory Limit: 128 MB Submit: 405 Solved: 160 [Submit][Status][Discuss] Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The planet is unsuitable for colo

2527: [Poi2011]Meteors

2527: [Poi2011]Meteors Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 1528  Solved: 556[Submit][Status][Discuss] Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The planet is unsuitable for col

bzoj 2527 Meteors - 整体二分 - 树状数组

Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The planet is unsuitable for colonisation due to strange meteor showers, which on the other hand make it an exceptionally interesting object of st

【BZOJ-2527】Meteors 整体二分 + 树状数组

2527: [Poi2011]Meteors Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 831  Solved: 306[Submit][Status][Discuss] Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The planet is unsuitable for colo

[Poi2011] Meteors(从不知所措到整体二分)

Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The planet is unsuitable for colonisation due to strange meteor showers, which on the other hand make it an exceptionally interesting object of study. The mem

CH4912 Meteors

题意 4912 Meteors 0x49「数据结构进阶」练习 描述 Byteotian Interstellar Union有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第1份相邻),第i份上有第Ai个国家的太空站. 这个星球经常会下陨石雨.BIU已经预测了接下来K场陨石雨的情况. BIU的第i个成员国希望能够收集Pi单位的陨石样本.你的任务是判断对于每个国家,它需要在第几次陨石雨之后,才能收集足够的陨石. Byteotian Interstellar Union (

Python爬虫|深入请求(四)常见的反爬机制以及应对方法

作者:David Qian 链接:https://zhuanlan.zhihu.com/p/21558661 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 大家好!我是厦门大学王亚南经济研究院的大一学生,今天将由我来为大家介绍一下常见的反爬机制以及应对方法. 注:非商业转载注明作者即可,商业转载请联系作者授权并支付稿费.本人已授权"维权骑士"网站(http://rightknights.com)对我在知乎发布文章的版权侵权行为进行追究与维权. ---

基于自适应热补丁的Android内核漏洞生态修复方案

1. 背景 Android内核漏洞严重影响了Android平台的安全.一旦内核被攻破,所有依赖内核完整性的安全机制都岌岌可危(比如加密.进程隔离.支付.指纹验证等).作为Android平台最后的防线,TrustZone也会受到威胁,因为内核可以从很多被信任的接口向TrustZone发起攻击.因此,理想情况下Android生态圈应该及时消灭内核漏洞.然而从Google的Android Security Bulletin上看,Android内核漏洞的数量呈飞快上涨的趋势(Figure 1所示).虽然