直线上有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-网络编程29

    1. 网络编程入门 1.1 网络编程概述 1.2 网络编程三要素 1.3 IP地址 在命令提示符中使用 1.4 InetAddress的使用 代码示例: public class InetAddres ...

  2. 安装Go语言支持及Gogs版本管理工具

    安装Go语言支持及Gogs版本管理工具 1. GO 语言: 1.1 介绍 1.1.1 官方介绍: The Go programming language is an open source proje ...

  3. 一定要收藏的5个优秀的SpringCloud开源项目

    上一期为大家推荐了几个前端模板,没看过的点下面 一定要收藏的5个后台管理系统的前端框架 今天再为大家推荐几个优秀的SpringCloud开源脚手架项目,开箱即用,不管是学习还是开发新项目,都非常不错. ...

  4. 【贪心+排序】排队接水 luogu-1223

    题目描述 有n个人在一个水龙头前排队接水,假如每个人接水的时间为Ti,请编程找出这n个人排队的一种顺序,使得n个人的平均等待时间最小. 分析 注意要开longlong AC代码 #include &l ...

  5. 【贪心】数列分段Section I luogu-1181

    题目描述 对于给定的一个长度为\(N\)的正整数数列\(A_i\),现要将其分成连续的若干段,并且每段和不超过\(M\)(可以等于\(M\)),问最少能将其分成多少段使得满足要求. 分析 简单思考一下 ...

  6. 【知识详解】Https详解

    Https详解 1.什么是Https Http + SSL = Https 一句话说:Https是身披SSL的Http,当使用了SSL后,Http先和SSL通信,再由SSL和TCP通信, 2.为什么需 ...

  7. 第十一篇 -- QMainWindow与QAction(斜体-粗体-下划线)

    效果图: ui_mainWindow.py # -*- coding: utf-8 -*- # Form implementation generated from reading ui file ' ...

  8. Spring Cloud专题之五:config

    书接上回: SpringCloud专题之一:Eureka Spring Cloud专题之二:OpenFeign Spring Cloud专题之三:Hystrix Spring Cloud 专题之四:Z ...

  9. ifix历史数据(H04/H08/H24)转换为CSV文件导出

    在最近的一次环保数据维护中,由于自己疏忽导致数据库中TP值并未有效记录,还好历史趋势有相关记录,问题是我该如何将.H24文件记录导出?在逛论坛后,无意发现一款工具解决了我的燃眉之急-HTD2CSV.e ...

  10. jquery.autocomplete 使用解析

    页面引用 <script type="text/javascript" src="${base}/autocom/jquery-1.8.2.min.js" ...