题意:给出指路石的范围,问最小需要几个指路石可以覆盖所有的军队。

题解:排序一遍,然后扫出起始区间和终止区间,就可以求出最小的覆盖数了

ac代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
cin.sync_with_stdio(false);
int n,m;
int a[];
while(cin>>n>>m)
{
if(n==- && m==-) break;
for(int i=;i<=m;i++) cin>>a[i];
sort(a+,a++m);
int ans=;
int flag=;// 0->start 1->end
int pos;
int i=;
while(i<=m)
{
if(flag==)
{
int temp=a[i]+n;
// cout<<temp<<endl;
while(a[i]<=temp) i++;
i--;
flag=;
ans++;
}
else
{
int temp=a[i]+n;
while(a[i]<=temp) i++;
flag=;
}
}
cout<<ans<<endl;
}
return ;
}

最新文章

  1. BZOJ 3365 Distance Statistics 点分治
  2. Windows环境下的NodeJS+NPM+Bower安装配置步骤
  3. Redis 初
  4. JavaScript:通过id来进行元素的取得
  5. [原创]java WEB学习笔记65:Struts2 学习之路--Struts的CRUD操作( 查看 / 删除/ 添加) ModelDriven拦截器 paramter 拦截器
  6. 将table导出为Excel的标准无乱码写法
  7. OkHttp 详解
  8. [剑指OFFER] 数组中的逆序对
  9. Java 实现 Domino邮箱自动注册
  10. 【集美大学1411_助教博客】团队作业1——团队展示&amp;选题 成绩
  11. Go学习——go+channel实战(转)
  12. 将Python 程序打包成 .exe格式入门
  13. Service-Level Agreement (服务水平协议)
  14. JavaScript拼接html字符串时截断问题
  15. Bizatlk Accelerator for RosettaNet安装与配置
  16. 使用ssh服务管理远程主机
  17. tensorflow之数据读取探究(2)
  18. abap function module中的异常处理
  19. pytorch 中的 split
  20. day 31 表单标签,CSS

热门文章

  1. base64和hex
  2. Flutter移动电商实战 --(47)详细页_Flutter_html插件的使用
  3. 留个纪念,过了这么多年,又干回Android了!
  4. spark简单文件配置
  5. 【Leetcode_easy】724. Find Pivot Index
  6. MFC BASE64加解密 算法
  7. 【ARTS】01_30_左耳听风-201900603~201900609
  8. iOS-宏定义
  9. 云计算和 AWS 概述(一)
  10. VMware虚拟机中CentOS7的硬盘空间扩容