poj 3069 继续弱鸡的贪心
2024-09-05 03:05:35
题意:给出指路石的范围,问最小需要几个指路石可以覆盖所有的军队。
题解:排序一遍,然后扫出起始区间和终止区间,就可以求出最小的覆盖数了
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 ;
}
最新文章
- BZOJ 3365 Distance Statistics 点分治
- Windows环境下的NodeJS+NPM+Bower安装配置步骤
- Redis 初
- JavaScript:通过id来进行元素的取得
- [原创]java WEB学习笔记65:Struts2 学习之路--Struts的CRUD操作( 查看 / 删除/ 添加) ModelDriven拦截器 paramter 拦截器
- 将table导出为Excel的标准无乱码写法
- OkHttp 详解
- [剑指OFFER] 数组中的逆序对
- Java 实现 Domino邮箱自动注册
- 【集美大学1411_助教博客】团队作业1——团队展示&;选题 成绩
- Go学习——go+channel实战(转)
- 将Python 程序打包成 .exe格式入门
- Service-Level Agreement (服务水平协议)
- JavaScript拼接html字符串时截断问题
- Bizatlk Accelerator for RosettaNet安装与配置
- 使用ssh服务管理远程主机
- tensorflow之数据读取探究(2)
- abap function module中的异常处理
- pytorch 中的 split
- day 31 表单标签,CSS