poj 3069 继续弱鸡的贪心
题意:给出指路石的范围,问最小需要几个指路石可以覆盖所有的军队。
题解:排序一遍,然后扫出起始区间和终止区间,就可以求出最小的覆盖数了
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 继续弱鸡的贪心的更多相关文章
- poj 3069 Saruman's Army (贪心)
简单贪心. 从左边开始,找 r 以内最大距离的点,再在该点的右侧找到该点能覆盖的点.如图. 自己的逻辑有些混乱,最后还是参考书上代码.(<挑战程序设计> P46) /*********** ...
- POJ 3069——Saruman's Army(贪心)
链接:http://poj.org/problem?id=3069 题解 #include<iostream> #include<algorithm> using namesp ...
- poj 3069 Saruman's Army(贪心)
Saruman's Army Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tot ...
- POJ 3617 Best Cow Line ||POJ 3069 Saruman's Army贪心
带来两题贪心算法的题. 1.给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下面两个操作:1.从S的头部删除一个字符,加到T的尾部.2.从S的尾部删除一个字符,加 ...
- poj 3069 Saruman's Army 贪心 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=3069 题解 题目可以考虑贪心 尽可能的根据题意选择靠右边的点 注意 开始无标记点 寻找左侧第一个没覆盖的点 再来推算既可能靠右的标记点为一 ...
- POJ 3069 Saruman's Army(贪心)
Saruman's Army Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- POJ 3069 Saruman's Army(萨鲁曼军)
POJ 3069 Saruman's Army(萨鲁曼军) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] Saruman ...
- poj 3617 弱鸡贪心
比赛的时候扣了一道贪心的题目,不会写,,现在补一补一些基础的贪心. 题意:给定一个字符串s,要求按下列操作生成一个新串t--每次从s串中的最前和最后取一个字符给t,要求生成的t字典序最小. 题解:由于 ...
- poj 3069 贪心+区间问题
Saruman's Army Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3056 De ...
随机推荐
- 自然语言处理基础与实战(8)- 主题模型LDA理解与应用
本文主要用于理解主题模型LDA(Latent Dirichlet Allocation)其背后的数学原理及其推导过程.本菇力求用简单的推理来论证LDA背后复杂的数学知识,苦于自身数学基础不够,因此文中 ...
- 程序中的.htaccess文件是做什么的
程序中的.htaccess文件是做什么的 一.总结 一句话总结: htaccess=ht(Hypertext)+access=超文本入口 覆盖Apache服务器的默认配置 .htaccess(超文本访 ...
- arcgis python 刷新
arcpy.RefreshActiveView() 刷新地图和布局窗口 arcpy.RefreshTOC() 刷新内容列表 arcpy.RefreshCatalog(r"F:\tknew10 ...
- IIS URL Rewriting and ASP.NET Routing
IIS URL Rewriting and ASP.NET Routing With the release of the URL Rewrite Module for IIS and the inc ...
- OSError: image file is truncated (28 bytes not processed)
解决办法: 在代码中添加两行 from PIL import ImageFile ImageFile.LOAD_TRUNCATED_IMAGES = True
- 阶段5 3.微服务项目【学成在线】_day17 用户认证 Zuul_06-用户认证-认证服务查询数据库-Bcrypt介绍
演示MD5加密的方式 数据库内的数据密码虽然都是6个1但是 每次加密出来的字符串是不一样的 加盐 测试BCrpty 循环10次加密 密码的校验 比人工的加盐要方便的多 这是创建的一个Spring的Be ...
- 雨田家园 delphi 拆分字符串
最近在使用Delphi开发一种应用系统的集成开发环境.其中需要实现一个字符串拆分功能,方法基本原型应该是:procedure SplitString(src: string ; ch: Char; v ...
- sonarqube-jenkins-config
Sonar Config .Jenkinsfile config stage('SonarQube analysis') { steps { script { scannerHome = tool ' ...
- MongoDB集群之分片技术应用 —— 学习笔记
课程链接:https://www.imooc.com/learn/501 一.什么是分片? 分片:将数据进行2拆分,将数据水平的分散到不同的服务器上. 二.为什么要分片? 架构上:读写均衡.去中心化 ...
- c-lodop的三个进程和一个服务介绍
在windows任务管理器里,最新版可以看到有三个进程,例如安32位c-lodop的时候,有CLodopPrint32.exe.CLodopPrint32_backup.exe.CLodopServi ...