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

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

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 ;
}

poj 3069 继续弱鸡的贪心的更多相关文章

  1. poj 3069 Saruman's Army (贪心)

    简单贪心. 从左边开始,找 r 以内最大距离的点,再在该点的右侧找到该点能覆盖的点.如图. 自己的逻辑有些混乱,最后还是参考书上代码.(<挑战程序设计> P46) /*********** ...

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

    链接:http://poj.org/problem?id=3069 题解 #include<iostream> #include<algorithm> using namesp ...

  3. poj 3069 Saruman's Army(贪心)

    Saruman's Army Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Tot ...

  4. POJ 3617 Best Cow Line ||POJ 3069 Saruman's Army贪心

    带来两题贪心算法的题. 1.给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下面两个操作:1.从S的头部删除一个字符,加到T的尾部.2.从S的尾部删除一个字符,加 ...

  5. poj 3069 Saruman's Army 贪心 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=3069 题解 题目可以考虑贪心 尽可能的根据题意选择靠右边的点 注意 开始无标记点 寻找左侧第一个没覆盖的点 再来推算既可能靠右的标记点为一 ...

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

     Saruman's Army Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  7. POJ 3069 Saruman's Army(萨鲁曼军)

    POJ 3069 Saruman's Army(萨鲁曼军) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] Saruman ...

  8. poj 3617 弱鸡贪心

    比赛的时候扣了一道贪心的题目,不会写,,现在补一补一些基础的贪心. 题意:给定一个字符串s,要求按下列操作生成一个新串t--每次从s串中的最前和最后取一个字符给t,要求生成的t字典序最小. 题解:由于 ...

  9. poj 3069 贪心+区间问题

    Saruman's Army Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5989   Accepted: 3056 De ...

随机推荐

  1. RK3288 修改ddr频率

    转载请注明出处:https://www.cnblogs.com/lialong1st/p/10912334.html CPU:RK3288 系统:Android 5.1 RK3288 的 ddr 频率 ...

  2. Java并发包线程池之ForkJoinPool即ForkJoin框架(二)

    前言 前面介绍了ForkJoinPool相关的两个类ForkJoinTask.ForkJoinWorkerThread,现在开始了解ForkJoinPool.ForkJoinPool也是实现了Exec ...

  3. Java并发包线程池之ForkJoinPool即ForkJoin框架(一)

    前言 这是Java并发包提供的最后一个线程池实现,也是最复杂的一个线程池.针对这一部分的代码太复杂,由于目前理解有限,只做简单介绍.通常大家说的Fork/Join框架其实就是指由ForkJoinPoo ...

  4. ISO/IEC 9899:2011 条款6.4.4——常量

    6.4.4 常量 语法 1.constant: integer-constant floating-constant enumeration-constant character-constant 约 ...

  5. HTTP连接详解

  6. nginx conf 文件

    server { listen ; server_name local.light.com; index index.html index.htm index.php; root /home/wwwr ...

  7. Composer更新慢的终极解决方案-转

    转自:http://blog.csdn.net/fishermanmax/article/details/51975692 Packagist 镜像 请各位使用本镜像的同学注意: 本镜像已经依照 co ...

  8. Java解压tar.Z文件(使用Apache Commons-compress)

    这里使用apache commons compress对.tar.Z格式文件进行解压. 对于一个文件test.tar.Z,我们可以将解压过程理解为: 将test.tar.Z解压为test.tar: 将 ...

  9. Docker Machine(十五)

    目录 一.Docker Machine 总览 1.Docker Engine VS Docker Machine 2.环境准备 二.安装 Docker Machine 1.Install Machin ...

  10. 如何区分浏览器发起的是基于http/1.x还是http/2的请求?

    前言      随着2015年http2.0被推出以来,主流的现代浏览器大多都开始慢慢去实现这个协议,那么如果查看自己的浏览器是否支持发送http2.0的请求,或者如何查看浏览器发送的请求是基于哪一个 ...