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 ...
随机推荐
- Uncaught SyntaxError : Unexpected token ILLEGAL js传递带空格的参数
通常在页面中要让某些内容点击后产生点击事件(非页面跳转)都会使用onclick,但是这样不适于需要传递参数的情况,于是写成直接调用JavaScript函数的方式:<a href=javascri ...
- [深入react] 4.牛逼闪闪的虚拟DOM
React.createElement嵌套后的结果就是虚拟dom,虚拟dom听着很高端,其实就是一个json,类似: { type:'div', props:{ className:"box ...
- 阿里云OS和Android的关系(本文转载月光博客)
原博客地址:http://www.williamlong.info/archives/3222.html 近日,有关谷歌Android和阿里云的争论闹得沸沸扬扬,谷歌高管.Android开发领头人An ...
- qt: flush: BitBlt failed
"BitBlt" is a graphics accelerator function. The message is a warning, not an error. It te ...
- Java学习笔记——JDBC读取properties属性文件
Java 中的 properties 文件是一种配置文件,主要用于表达配置信息,文件类型为*.properties,格式为文本文件. 文件的内容是格式是"键=值"(key-valu ...
- gcc -L -l的使用
-l参数就是用来指定程序要链接的库,-l参数紧接着就是库名,那么库名跟真正的库文件名有什么关系呢?就拿数学库来说,他的库名是m,他的库文件名是libm.so,很容易看出,把库文件名的头lib和尾.so ...
- 10个最实用的Linux命令
收集了一些对于Linux新手最基本但最有用的Linux命令.你完全可以键入这些命令来管理你的服务器.这些命令对于学习vps或服务器管理的新手最为简便.1.List命令 ls -a //列出所有文件 l ...
- PhoneGap移动开发框架
phonegap是一个跨平台的移动app开发框架,可以把html css js写的页面打包成跨平台的可以安装的移动app,并且可以调用原生的几乎所有的功能,比如摄像头,联系人,加速度等 看到一篇 ...
- C#高级知识点概要(1) - 委托和事件
本文目录: 委托 委托的简单使用 用委托实现插件式编程 多播委托 静态方法和实例方法对于委托的区别 泛型委托 Func 和 Action 委托 委托的兼容 事件 事件的基本使用 事件的标准模式 委托 ...
- 树莓派编译C++
首次研究树莓派~ 安装的Linux 编译C++时,就出现了问题,未定义!!无法识别 查了原因是没有安装 build-essential 解决方法 sudo apt-get install buil ...