直线上有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. Java基础00-集合基础15

    1. 集合基础 1.1 集合概述 1.2 ArrayList构造方法和添加方法 代码示例: 想通过指定索引添加到最后一个位置的话就填写,现有索引的+1,比如3个索引就是4.如果在指定索引的位置添加没有 ...

  2. K8s基本概念资料

    https://www.cnblogs.com/menkeyi/p/7134460.html

  3. Python+js进行逆向编程加密MD5格式

    一.安装nodejs 二.安装:pip install PyExecJs 三.js源文件Md5格式存放本地,如下 var n = {}function l(t, e) {var n = (65535 ...

  4. 《PHP 实现 Base64 编码/解码》笔记

    前言 早在去年 11 月底就已经看过<PHP 实现 Base64 编码/解码>这篇文章了,由于当时所掌握的位运算知识过于薄弱,所以就算是看过几遍也是囫囵吞枣一般,不出几日便忘记了其滋味. ...

  5. 解析ArrayList的底层实现(上)

    private static final long serialVersionUID = 8683452581122892189L;//唯一序列号ID private static final int ...

  6. informix 数据库锁表分析和解决方法

    一.前言 在联机事务处理(OLTP)的数据库应用系统中,多用户.多任务的并发性是系统最重要的技术指标之一.为了提高并发性,目前大部分RDBMS都采用加锁技术.然而由于现实环境的复杂性,使用加锁技术又不 ...

  7. PostgreSQL-WITH AS短语

    WITH提供了一种方式来书写在一个大型查询中使用的辅助语句.这些语句通常被称为公共表表达式或CTE,它们可以被看成是定义只在一个查询中存在的临时表.在WITH子句中的每一个辅助语句可以是一个SELEC ...

  8. odoo时间过滤

    Odoo中本日.本月.上月过滤器实现方法   Odoo中本日.本月.上月过滤器实现方法<filter string="今日订单" name="today" ...

  9. C# JSON学习之序列化与反序列化

    在我的个人计划中,学习制作c#下的曲线平台属于下半年的重点.关于前后端的数据传递-json数据的学习很有必要,通过一个例子来加深自己的理解. 新建一个console控制台程序,通过导入NewstonS ...

  10. sqli-labs靶机

    第一关   1' 第二关   1 第三关    1') 第四关    1'') 第五关   1'     +         extractvalue报错注入 第六关   1 "  +    ...