Saruman's Army

时间:2021-02-08 12:52:08   收藏:0   阅读:0

技术图片

 

#include<cstdio>
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
set<int> s;
int main(void)
{
    int R, n;
    while (cin >> R >> n && R != -1 && n != -1)
    {
        s.clear();
        for (int i = 0; i < n; i++) { int t; cin >> t; s.insert(t); }
        int ans = 0;
        set<int>::iterator it = s.begin();
        while (it != s.end())
        {
            //要想使用的标志最少,从左边的点开始考虑
            int x = *it; it++;
            //距其R的距离以内必须带有标志,所以距离最左边R的距离最靠边缘的点为标志点
            while (it != s.end() && *it <= x + R)it++;
            ans++;
            //以标志点为中心
            int y = *(--it); it++;
            //寻找中心点右边的边缘外的第一个点,找到后开始依次循环
            while (it != s.end() && *it <= y + R)it++;
        }
        printf("%d\n", ans);
    }
    return 0;

}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!