http://poj.org/problem?id=3069

Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep track of his forces, Saruman distributes seeing stones, known as palantirs, among the troops. Each palantir has a maximum effective range of R units, and must be carried by some troop in the army (i.e., palantirs are not allowed to “free float” in mid-air). Help Saruman take control of Middle Earth by determining the minimum number of palantirs needed for Saruman to ensure that each of his minions is within R units of some palantir.

Input

The input test file will contain multiple cases. Each test case begins with a single line containing an integer R, the maximum effective range of all palantirs (where 0 ≤ R ≤ 1000), and an integer n, the number of troops in Saruman’s army (where 1 ≤ n ≤ 1000). The next line contains n integers, indicating the positions x1, …, xn of each troop (where 0 ≤ xi ≤ 1000). The end-of-file is marked by a test case with R = n = −1.

Output

For each test case, print a single integer indicating the minimum number of palantirs needed.

Sample Input

0 3
10 20 20
10 7
70 30 1 7 15 20 50
-1 -1

Sample Output

2
4 这道题讲的是白巫师要带领他的军队从一个地方到另外一个地方,走直线,但是为了监控他的军队嘞,他就用一种石头放在其中一个人身上,然后这个石头有r米的监控范围,问至少需要
多少石头(大概就是这个意思,我英语也不好啊[大哭])
然后就开始想代码,我想的是,中间一个人拿石头,那就可以监控两边的人啊,所以从第一个开始,一直向后……

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,r,a[1010];
    while(scanf("%d%d",&r,&n)==2&&n!=-1&&r!=-1)
    {
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);

sort(a,a+n);
        int sum=0,i=0;
        while(i<n)
        {
            int x=a[i];
            i++;
            while(i<n && a[i]-x<=r) i++;//这个是判断距离0处有r的点,因为有个i++,所以i=过了r距离之后的第一个i
            int p=a[i-1];//所以这个就是拿着石头的人
            while(i<n && a[i]-p<=r) i++;//这个就是右边有r的距离
            sum++;
        }
        printf("%d\n",sum);
    }
    return 0;
}

poj3069 Saruman's Army的更多相关文章

  1. POJ3069 Saruman's Army【贪心】

    Saruman the White must lead his army along a straight path from Isengard to Helm's Deep. To keep tra ...

  2. poj3069 Saruman's Army(贪心)

    https://vjudge.net/problem/POJ-3069 弄清楚一点,第一个stone的位置,考虑左右两边都要覆盖R,所以一般情况下不会在左边第一个(除非前两个相距>R). 一开始 ...

  3. Saruman's Army(POJ3069)

    Description Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. ...

  4. poj 3069 Saruman's Army

    Saruman's Army Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8477   Accepted: 4317 De ...

  5. POJ 3069 Saruman's Army(萨鲁曼军)

    POJ 3069 Saruman's Army(萨鲁曼军) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] Saruman ...

  6. POJ 3069 Saruman's Army(贪心)

     Saruman's Army Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  7. POJ 3069:Saruman's Army

    Saruman's Army Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13242   Accepted: 6636 D ...

  8. poj 3069 Saruman's Army(贪心)

    Saruman's Army Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Tot ...

  9. Saruman's Army(贪心)

    Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep tra ...

随机推荐

  1. kafka模块概述

    简介 kafka主要用于实现低延迟的发送和收集大量的事件和日志数据--通常是活跃的数据(PV.访问记录等),数据以日志形式记录下来,然后由一个专门的系统来进行日志的收集与统计: 吞吐量极高的分布式消息 ...

  2. 基于FormsAuthentication的用户、角色身份认证

    一般情况下,在我们做访问权限管理的时候,会把用户的正确登录后的基本信息保存在Session中,以后用户每次请求页面或接口数据的时候,拿到 Session中存储的用户基本信息,查看比较他有没有登录和能否 ...

  3. Linux-001-nmon系统性能监控工具的使用及报表产出

    在进行性能测试的时候,需要获取服务器的各项指标,例如 CPU.MEM.I/O.DISK 等.网上有很多的监控工具,nmon 就是其中的一个,其可与 JMeter结合使用,测试系统的性能.其概要的介绍, ...

  4. RPM包管理命令rpm

    RPM包管理器是Linux系统中最早的软件包管理软件之一,也是目前最流行的软件包管理器,许多发行版都使用RPM作为默认的软件包管理软件. RPM软件包名称格式: samba-client-3.0.33 ...

  5. 来杯Caffe——在ubuntu下安装Caffe框架并测试

    Caffe是一种深度学习框架...blablabla...... Caffe要在ubuntu下安装 1. 安装依赖 sudo apt-get install libatlas-base-dev sud ...

  6. 深入理解js的prototype以及prototype的一些应用

    上一篇讲了js的prototype概念,在这里回顾一下prototype的定义: prototype是函数的一个属性,并且是函数的原型对象.引用它的必然是函数,这个应该记住. 但是,很奇怪,各位看官, ...

  7. 对bootstrap中confirm alert进行封装

    HTML: <!-- system modal start --> <div id="ycf-alert" class="modal"> ...

  8. 使用Cordova编译Android平台程序提示:Could not reserve enough space for 2097152KB object heap

    大体的意思是系统内存不够用,创建VM失败.试了网上好几种方法都不行,最后这个方法可以了: 开始->控制面板->系统->高级设置->环境变量->系统变量 新建变量: 变量名 ...

  9. c++中vector的用法详解

    c++中vector的用法详解 vector(向量): C++中的一种数据结构,确切的说是一个类.它相当于一个动态的数组,当程序员无法知道自己需要的数组的规模多大时,用其来解决问题可以达到最大节约空间 ...

  10. UE4入门与精通

    由于目前在使用UE4引擎,多少也有一些心得,比如在日常使用中会遇到一些问题.坑(潜规则)或者一些使用技巧等.本人决定开一个大坑,主要有两个目的:一是可以自己做个记录,二是可以给大家提供一些参考吧.主要 ...