Saruman's Army (POJ 3069)
直线上有N个点。点i的位置是Xi。从这N个点中选择若干个,给它们加上标记。对每一个点,其距离为R以内的区域里必须又带有标记的点(自己本身带有标记的点,可以认为与其距离为0的地方有一个带有标记的点)。在满足这个条件的情况下,希望能为尽可能少的点添加标记。请问至少要有多少点被加上标记?
#include "iostream"
#include "algorithm"
using namespace std; const int MAX_N = 1000;
int N=6, R=10;
int X[MAX_N] = {1,7,15,20,30,50}; void solve() {
sort(X,X+N);
int i = 0, ans = 0;
while (i<N)
{
//S为最左侧没有被覆盖的点
int S = X[i++];
//一直向右前进直到距离S的距离大于R的点
while (i<N && X[i]<=S+R) i++;
//P是新加上标记的点的位置
int P = X[i-1];
//一直向右前进找到距离P的距离大于R的点
while (i<N && X[i]<=P+R) i++;
ans++;
}
cout << ans << endl;
} int main() {
solve();
system("pause");
return 0;
}#include "iostream"
#include "algorithm"
using namespace std; const int MAX_N = 1000;
int N=6, R=10;
int X[MAX_N] = {1,7,15,20,30,50}; void solve() {
sort(X,X+N);
int i = 0, ans = 0;
while (i<N)
{
//S为最左侧没有被覆盖的点
int S = X[i++];
//一直向右前进直到距离S的距离大于R的点
while (i<N && X[i]<=S+R) i++;
//P是新加上标记的点的位置
int P = X[i-1];
//一直向右前进找到距离P的距离大于R的点
while (i<N && X[i]<=P+R) i++;
ans++;
}
cout << ans << endl;
} int main() {
solve();
system("pause");
return 0;
}
Saruman's Army (POJ 3069)的更多相关文章
- Q - Saruman's Army POJ - 3069
Saruman the White must lead his army along a straight path from Isengard to Helm's Deep. To keep tra ...
- 贪心-Saruman‘s Army POJ - 3069
万恶之源 目录 题意 思路 贪心的原则是什么呢? 错解 正解 代码实现 书上的代码 我的代码 比较一下 问题 题意 给定若干个点的坐标,与范围R.每个点可以选择是否标记,标记后这个点的左右范围R内的所 ...
- POJ 3069 Saruman's Army(萨鲁曼军)
POJ 3069 Saruman's Army(萨鲁曼军) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] Saruman ...
- POJ 3069 Saruman's Army(贪心)
Saruman's Army Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- 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
Saruman's Army Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8477 Accepted: 4317 De ...
- POJ 3069:Saruman's Army
Saruman's Army Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13242 Accepted: 6636 D ...
- poj 3069 Saruman's Army(贪心)
Saruman's Army Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tot ...
- POJ 3069 Saruman's Army
Saruman's Army Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6688 Accepted: 3424 De ...
随机推荐
- 数据库版本管理工具Flyway(4.0.3)---工作机制(译文)
How Flyway works The easiest scenario is when you point Flyway to an empty database. 最容易的方案是Flyway指向 ...
- [Qt] IP地址输入框实现
封装了一个ip地址的输入框.网络上下载了份代码,找不到哪里的了.经过修改之后,尽力让它的行为和windows的IP地址输入框的行为看起来像些.代码如下: //ipaddredit.h #ifndef ...
- bat文件调用shutdown命令不生效问题原因
背景: 本人使用云桌面办公,但是用于登陆云桌面的终端运行卡顿,每次开机要20min才能登陆云桌面,所以: 1)在BIOS设置了定时开关,让终端提前开机 2)在系统上层,开机启动项增加一个bat文件(s ...
- ETL-Career RoadMap
RoadMap: 1.Tester:sql的单体或批处理测试: 2. Application Developer 2.1 批处理手动工具(如何使用.如何调度批处理.如何生成批处理脚本): 2.2 批处 ...
- android避免decodeResource图片时占用太大的内存
增加largeHeap="true"属性. android:largeHeap Whether your application's processes should be cre ...
- 使用zTree控件制作的表格形式的树形+数据菜单
測试了一下,兼容ie7以上, chrome opera ff 不使用对方css /*------------------------------------- zTree Style version: ...
- JavaScript兼容问题汇总[实时更新]
印象笔记链接地址:点我查看 遇到问题不断更新中-- [转载请注明出处-HTML5自由者]
- [开源夏令营][四] Docker remote API 之 镜像篇
列出镜像 列出镜像,有两个可选參数,一个是all,一个是filter,all可选值有,0/False/false,1/True/true,默觉得0:filter是一个包括一个过滤对象的json,形式如 ...
- android 多项对话框
在main.xml中 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...
- URL与URI的区别
URI—Universal Resource Identifier通用资源标志符Web上可用的每种资源如HTML文档.图像.视频片段.程序等都是一个来URI来定位的URI一般由三部组成①访问资源的命名 ...