直线上有N个点。 点i的位置是Xi。从这N个点中选择若干个,给它们加上标记。 对每一个点,其距离为R以内的区域里必须有带有标记的点(自己本身带有标记的点, 可以认为与其距离为 0 的地方有一个带有标记的点)。 在满足这个条件的情况下, 希望能为尽可能少的点添加标记。 请问至少要有多少点被加上标记?

输入

N = 6
R = 10
X = (1, 7, 15, 20, 30, 50}

输出

3

java实现

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int r = scn.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++) {
arr[i]=scn.nextInt();
}
int flag=0;
int sum=0;
while(flag<n) {
int num = arr[flag];
while(arr[flag]<=num+r) {
flag++;
if(flag>=n) break;
}
flag--;
num = arr[flag];
while(arr[flag]<=num+r) {
flag++;
if(flag>=n) break;
}
sum++;
}
System.out.println(sum);
} }

Saruman's Army的更多相关文章

  1. poj 3069 Saruman's Army

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

  2. poj3069 Saruman's Army

    http://poj.org/problem?id=3069 Saruman the White must lead his army along a straight path from Iseng ...

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

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

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

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

  5. Saruman's Army(POJ3069)

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

  6. POJ 3069:Saruman's Army

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

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

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

  8. Saruman's Army(贪心)

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

  9. POJ 3069 Saruman's Army (模拟)

    题目连接 Description Saruman the White must lead his army along a straight path from Isengard to Helm's ...

  10. POJ3069 Saruman's Army【贪心】

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

随机推荐

  1. nacos配置本地多个实例(伪集群)

    在本地配置多个nacos实例(伪集群),一般就是配置多个nacos端口,并启动多个startup.sh脚本.网上一些博客通过修改startup.sh脚本来指定不同nacos端口,比如:./startu ...

  2. 祝贺|合肥.NET俱乐部第二期技术沙龙活动圆满成功

    热烈祝贺合肥.NET俱乐部第二期技术沙龙圆满成功,感恩参与活动的每一位小伙伴!正是因为有你们才促成了这次聚会的成功.现对此次活动进行简单回顾并附上精彩的活动图片,每一位参与活动者名单,以及此次活动讲师 ...

  3. CentOS7创建个人系统启动服务项的方法

    CentOS7.6自定义系统启动项的方法(类似busybox里面的inittab)1.编写属于自己的unit服务文件,命令为my.service[Unit]Description=My-demo Se ...

  4. tomcat与springmvc 结合 之---第18篇 StandContext容器和SpringMVC的监听器的模型

    writedby张艳涛 如何使用tomcat的监听器 public class BootStrap_ex06 { public static void main(String[] args) { Ht ...

  5. CAS 原理 应用

    原子CAS操作 原子操作指令里,有原子加,原子减,cas到底是什么呢? 首先看一段代码, bool compare_and_swap(int *accum, int *dest, int newval ...

  6. Hotel 旅馆, 线段树查询,合并

    C. Hotel 旅馆 内存限制:256 MiB 时间限制:1000 ms 标准输入输出 题目类型:传统 评测方式:文本比较   题目描述 OIER最近的旅游计划,是到长春净月潭,享受那里的湖光山色, ...

  7. CVE-2021-3156 复现

    测试环境 OS: Ubuntu 18.04.5 LTS GCC: gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) Make: GNU Make 4.1 ...

  8. OEM 刷新配置方法

    一:设置>添加目标>配置自动搜索 二:主机上的目标>针对所选的主机 三:禁用调度 四:设置>添加目标>自动搜索结果 五:主机上的目标,搜索结果 六:删除 七:选择机器数据 ...

  9. Spring boot无法显示jsp页面问题汇总

    问题1: o.s.w.s.r.ResourceHttpRequestHandler:Path with "WEB-INF" or "META-INF": [WE ...

  10. 常用的IDEA快捷键

    常用的IDEA快捷键 代码右移:TAB键 代码左移:shift+TAB键 代码上移:shift+alt +方向键上 代码下移:shift+alt +方## 标题向键下 格式化代码 : ctrl +sh ...