Saruman's Army
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10994   Accepted: 5555

Description

Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep track of his forces, Saruman distributes seeing stones, known as palantirs, among the troops. Each palantir has a maximum effective range of R units, and must be carried by some troop in the army (i.e., palantirs are not allowed to “free float” in mid-air). Help Saruman take control of Middle Earth by determining the minimum number of palantirs needed for Saruman to ensure that each of his minions is within R units of some palantir.

Input

The input test file will contain multiple cases. Each test case begins with a single line containing an integer R, the maximum effective range of all palantirs (where 0 ≤ R ≤ 1000), and an integer n, the number of troops in Saruman’s army (where 1 ≤ n ≤ 1000). The next line contains n integers, indicating the positions x1, …, xn of each troop (where 0 ≤ xi ≤ 1000). The end-of-file is marked by a test case with R = n= −1.

Output

For each test case, print a single integer indicating the minimum number of palantirs needed.

Sample Input

0 3
10 20 20
10 7
70 30 1 7 15 20 50
-1 -1

Sample Output

2
4

Hint

In the first test case, Saruman may place a palantir at positions 10 and 20. Here, note that a single palantir with range 0 can cover both of the troops at position 20.

In the second test case, Saruman can place palantirs at position 7 (covering troops at 1, 7, and 15), position 20 (covering positions 20 and 30), position 50, and position 70. Here, note that palantirs must be distributed among troops and are not allowed to “free float.” Thus, Saruman cannot place a palantir at position 60 to cover the troops at positions 50 and 70.

题意:
给n个点,在每个点的r范围内必须要有一个标记。

贪心,从最左边开始找r内最远的点。

AC代码:

 //#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std; int a[]; int main(){
ios::sync_with_stdio(false);
int r,n;
while(cin>>r>>n&&r>=&&n>=){
memset(a,,sizeof(a));
for(int i=;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
int temp=,ans=;
while(temp<n){
int s=a[temp++];
while(temp<n&&a[temp]<=s+r){
temp++;
}
int cnt=a[temp-];
while(temp<n&&a[temp]<=cnt+r){
temp++;
}
ans++;
}
cout<<ans<<endl;
}
return ;
}

最新文章

  1. CentOS添加路由表
  2. Charted – 自动化的可视化数据生成工具
  3. neutron的基本原理
  4. C++静态成员函数小结(转)
  5. Unity中Mesh分解与边缘高亮加上深度检测
  6. coreData 深入理解4 --总结 (线程安全与同步--iOS5 前后对比)
  7. how to combine jpg + separate alpha in png?
  8. SVN--VisualSVN server 服务端和 TortoiseSVN客户端的基础使用
  9. Oracle默认的用户名和密码
  10. android学习日记13--数据存储之SharedPreference
  11. 【转】ArrayList和LinkedList的几种循环遍历方式及性能对比分析
  12. JavaScript 中的正常任务与微任务
  13. HIBERNATE - 符合Java习惯的关系数据库持久化(精华篇)
  14. 学习老外用webstorm开发nodejs的技巧--代码提示DefinitelyTyped
  15. Material使用07 MatGridListModule的使用
  16. thinkphp5z
  17. Servlet--HttpSession接口,HttpSessionContext接口,Cookie类
  18. 微信小程序ios点击状态栏返回顶部不好使
  19. Python3 系列之 环境配置篇
  20. 第十三次CCF第四题 1803——04 博弈

热门文章

  1. mongo数据库中一条记录中某个属性是数组情形时 数据结构的定义
  2. sed相关
  3. Facebook Gradient boosting 梯度提升 separate the positive and negative labeled points using a single line 梯度提升决策树 Gradient Boosted Decision Trees (GBDT)
  4. Django创建项目及app
  5. Linux入门基础(三)——系统命令
  6. spring 获取bean的几种方式
  7. SlopeOne推荐算法
  8. Java7、Java8 安装卸载问题
  9. LeetCode:安排工作以达到最大收益【455】
  10. SDOI 2017 Day1