题目大意:直线上有N个点,点i的位置是Xi,从这N个点中选取若干,给他们加上标记,对每一个点,其距离为R以内的区域内必须有被标记的点。求至少需要多少个点被标记。

题目思路:设最左边的点:点p的坐标为x,那么离其距离为R的点的坐标为(x+R),我们应该标记的点应为坐标最接近且小于等于(x+R)的点p,则此时【x,p+R】范围内点点均被标记。依次进行下去,直到包含所有点为止。

#include<stdio.h>
#include<queue>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#define INF 0x3f3f3f3f
#define LL long long
#define MOD 100000007
#define MAXSIZE 10005using namespace std;int p[MAXSIZE];int main()
{int r,n;while(scanf("%d%d",&r,&n),r!=-1 && n!=-1){for(int i=0;i<n;i++)scanf("%d",&p[i]);sort(p,p+n);int ans = 0;int pos1=0,pos2=0;while(pos1 < n){int index = p[pos1] + r;pos2 = pos1;while(p[pos2] <= index)pos2++;ans++;index = p[pos2-1] + r;pos1 = pos2;while(p[pos1] <= index)pos1++;}printf("%d\n",ans);}return 0;
}

View Code

转载于:https://www.cnblogs.com/alan-W/p/7188033.html

POJ 3069 Saruman's Army (贪心)相关推荐

  1. 【题解】POJ 3069 Saruman's Army(贪心)

    POJ 3069 Saruman's Army 原题 https://vjudge.net/problem/POJ-3069 白种人萨鲁曼必须带领他的军队沿着从艾辛格到圣盔谷的直线前进.为了跟踪他的部 ...

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

    题目链接:http://poj.org/problem?id=3069 Description Saruman the White must lead his army along a straigh ...

  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

    题意 给n个点,从中选择若干个标记,在距离标记为r的范围内包含其他的点,最少需要几个标记,才能将所有的点包含在内 思路 贪心.先排序,从最左边的点开始找到此半径内最大的点,则此点就是第一个标记,以此类 ...

  5. POJ - 3069 Saruman's Army 萨鲁曼的大军 贪心 重庆一中高2018级竞赛班第三次测试 2016.7.24 Problem 2

    [问题描述] 萨鲁曼的大军正行进在一条笔直的道路上,由于是在夜晚行军,路上的石头严重地影响了行军速度.于是萨鲁曼决定预先在道路上安装一些路灯,以便士兵们能清楚地看到所有石头. 萨鲁曼给出n块石头的位置 ...

  6. POJ3069 Saruman's Army【贪心】

    问题链接:POJ3069 Saruman's Army. 题意简述:直线上有N个点.点i的距离是Xi.从这N个点中选取若干点加上标记.对于每个点,与其距离为R的范围内必有做标记的点(包括自身).求至少 ...

  7. 贪心:Fence Repair、Saruman's Army

    Fence Repair Farmer John wants to repair a small length of the fence around the pasture. He measures ...

  8. 【ACM】POJ 3069

    [问题描述] Saruman the White must lead his army along a straight path from Isengard to Helm's Deep. To k ...

  9. Saruman's Army

    传送门 题目 Saruman the White must lead his army along a straight path from Isengard to Helm's Deep. To k ...

  10. Saruman's Army (POJ3069)

    Saruman's Army 萨鲁曼的大军正行进在一条笔直的道路上,由于是在夜晚行军,路上的石头严重地影响了行军速度.于是萨鲁曼决定预先在道路上安装一些路灯,以便士兵们能清楚地看到所有石头. 萨鲁曼给 ...

最新文章

  1. android 短信验证码的实现
  2. 从实例入手学习Shiro自定义Realm实现查询数据进行验证
  3. Object_id用法
  4. android 开发规范
  5. tempdb(转载)
  6. Unity中Invoke函数基础用法
  7. 使用OS X base System在线安装Mac OS到U盘及使用U盘恢复Mac OS
  8. 彻底去除2345好压的广告方法
  9. Windows命令--wmic
  10. 2022年上半年国家教师资格证考试
  11. lilo是什么意思_lilo是什么意思_lilo的用法_lilo造句_趣词词典
  12. Batman+joker乱谈
  13. 优盘连接时显示参数错误请问咋才能修复
  14. Github入门教程(新版)
  15. ubuntu 板载r8125有限网卡连接
  16. 学习opengl官方指南 01 opengl介绍
  17. jmeter之取样器(HTTP请求、调试取样器)
  18. cmd命令打开及切换目录路径
  19. 方式SingleTask 启动Intent设置 不能如愿打开需要的Activity
  20. pandas pandas具体用法相关内容(三)

热门文章

  1. HIVE 命令行操作和参数指引
  2. 蓝桥杯包子凑数-完全背包
  3. 不刷新改变/更换URL: pushState + Ajax
  4. LGOJP2831 愤怒的小鸟
  5. Java数据类型分类 1
  6. Spark standalone运行模式(图文详解)
  7. 关于erlang的-run 的启动参数
  8. [H5-Compress-Image]利用canvas实现 javascript 图片压缩处理_基于requirejs模块化的代码实现...
  9. POJ 1141 Brackets Sequence
  10. 条件随机场 Conditional Random Fields