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

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

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. CMMI基础知识扫盲

    CMMI全称是Capability Maturity Model Integration,CMMI是个好东西来的,但行内人士对她的认识并不全面,甚至有种种的误解.尽管网上有很多CMMI相关介绍,但一般 ...

  2. kvm网卡配置

    https://blog.51cto.com/quliren/2046001 https://blog.51cto.com/quliren/2045555 https://blog.csdn.net/ ...

  3. Windows 自动定时执行任务的方法

    windows 自动定时执行任务的几种实现方法   Task Schedul Windows自动定时执行任务,常见的方法有三种: Windows 任务计划程序 Windows Service SQL ...

  4. Mybatis 中的转义字符(转帖)

    下文来自:https://www.cnblogs.com/dato/p/7028723.html  在此感谢作者的辛勤付出. 记录以下mybatis中的转义字符,方便以后自己看一下 Mybatis转义 ...

  5. OpenJudge计算概论-数字求和

    /*========================================================= 数字求和 总时间限制: 1000ms 内存限制: 65536kB 描述 给定一个 ...

  6. vue+Typescript初级入门

    Typescript 在前端圈已经逐渐普及,Vue 2.5.0 改进了类型声明,使得对 TypeScript 更加友好 不过要想在项目中直接使用 TypeScript 仍然需要对项目进行一些改造 PS ...

  7. 论文翻译 DOTA:A Large-scale Dataset for Object Detection in Aerial Images

      简介:武大遥感国重实验室-夏桂松和华科电信学院-白翔等合作做的一个航拍图像数据集 摘要: 目标检测是计算机视觉领域一个重要且有挑战性的问题.虽然过去的十几年中目标检测在自然场景已经有了较重要的成就 ...

  8. osg::GraphicsContext::WindowingSystemInterface Screen Resolution(屏幕分辨率)

    unsigned int width, height; //获取系统分辨率 osg::GraphicsContext::WindowingSystemInterface *wsInterface = ...

  9. flutter编译ios的时候需要进行的操作:

    pod install  执行这个命令,安装依赖

  10. 28 Flutter 轮播图 flutter_swiper

    中文地址: https://github.com/best-flutter/flutter_swiper/blob/master/README-ZH.md 基本参数 参数 默认值 描述 scrollD ...