此题的策略是选取可用范围最右边的点,一般来说该点辐射两边,左侧辐射,右侧辐射,所以用两个循环,第一个循环找出该点,第二个循环求出最右边的点

源代码:

#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 1100
int main()
{
    int r,n,k=0,num=0,x,a[maxn];
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    cin>>r;
    while(k<n)
    {
        x=a[k];
        k++;
        while(k<n&&x+r>=a[k]) k++;
        x=a[k-1];
        while(k<n&&x+r>=a[k]) k++;
        num++;
    }
    cout<<num<<endl;
    return 0;
}

贪心法-------Saruman's army的更多相关文章

  1. Saruman's Army(贪心)

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

  2. POJ 3617 Best Cow Line ||POJ 3069 Saruman's Army贪心

    带来两题贪心算法的题. 1.给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下面两个操作:1.从S的头部删除一个字符,加到T的尾部.2.从S的尾部删除一个字符,加 ...

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

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

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

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

  5. POJ3069 Saruman's Army【贪心】

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

  6. poj 3069 Saruman's Army 贪心模拟

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

  7. B - B Saruman's Army(贪心)

    在一条直线上,有n个点.从这n个点中选择若干个,给他们加上标记.对于每一个点,其距离为R以内的区域里必须有一个被标记的点.问至少要有多少点被加上标记 Saruman the White must le ...

  8. 《挑战程序设计竞赛》2.2 贪心法-其它 POJ3617 3069 3253 2393 1017 3040 1862 3262

    POJ3617 Best Cow Line 题意 给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下列任意操作: 从S的头部(或尾部)删除一个字符,加到T的尾部 ...

  9. poj 3069 Saruman's Army

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

随机推荐

  1. MapReduce 论文阅读笔记

    Abstract MapReduce : programming model 编程模型 an associated implementation for processing and generati ...

  2. socketserver模块使用与源码分析

    socketserver模块使用与源码分析 前言 在前面的学习中我们其实已经可以通过socket模块来建立我们的服务端,并且还介绍了关于TCP协议的粘包问题.但是还有一个非常大的问题就是我们所编写的S ...

  3. The meaningless Game

    题目 Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting ...

  4. JavaScript基础使用parseInt()转换整数(005)

    parseInt()可以把一个字符串格式的整数解析一个整数数值,如"32 days"将被解析为32.这个函数还接受第二个参数,指定整数的进制(当然,一般来说应该是十进制).一个好的 ...

  5. sql 更新时 实现 数字字段自加1

    第一种:直接使用SQL语句,这种方式可以避免并发操作造成的数据不一致问题UPDATE 表名称 SET 列名称 = 列名称 + 1 WHERE …… 第二种:将上面的语句逻辑封装成一个存储过程,加上事务 ...

  6. pycharm一直显示Process finished with exit code 0

    后来排查发现原来是解释器的问题我之前使用的解释器是pycharm提供的虚拟解释器#####如何查看解释器点file–>new projects 如果选择的是2就是使用了pycharm提供的虚拟解 ...

  7. 关于位图数据和标记位-P3

    文章目录 1 背景 1.1 问题 2 问题1探究 2.1 没有区的情况 2.2 一个区的情况 2.3 两个区的情况 2.4 三个区的情况 2.5 四个区的情况 2.6 五个区的情况 3 问题2探究 3 ...

  8. (私人收藏)商务工作学习万能简约大气PPT模板

    商务工作学习万能简约大气PPT模板 https://pan.baidu.com/s/1aPnPZ285N5VSSErro1cPngehoa

  9. 02 . 分布式存储之FastDFS 高可用集群部署

    单节点部署和原理请看上一篇文章 https://www.cnblogs.com/you-men/p/12863555.html 环境 [Fastdfs-Server] 系统 = CentOS7.3 软 ...

  10. postcss.config.js not found

    https://github.com/ElemeFE/element/issues/10249