poj3069 Saruman's Army
http://poj.org/problem?id=3069
Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep track of his forces, Saruman distributes seeing stones, known as palantirs, among the troops. Each palantir has a maximum effective range of R units, and must be carried by some troop in the army (i.e., palantirs are not allowed to “free float” in mid-air). Help Saruman take control of Middle Earth by determining the minimum number of palantirs needed for Saruman to ensure that each of his minions is within R units of some palantir.
Input
The input test file will contain multiple cases. Each test case begins with a single line containing an integer R, the maximum effective range of all palantirs (where 0 ≤ R ≤ 1000), and an integer n, the number of troops in Saruman’s army (where 1 ≤ n ≤ 1000). The next line contains n integers, indicating the positions x1, …, xn of each troop (where 0 ≤ xi ≤ 1000). The end-of-file is marked by a test case with R = n = −1.
Output
For each test case, print a single integer indicating the minimum number of palantirs needed.
Sample Input
0 3
10 20 20
10 7
70 30 1 7 15 20 50
-1 -1
Sample Output
2
4 这道题讲的是白巫师要带领他的军队从一个地方到另外一个地方,走直线,但是为了监控他的军队嘞,他就用一种石头放在其中一个人身上,然后这个石头有r米的监控范围,问至少需要
多少石头(大概就是这个意思,我英语也不好啊[大哭])
然后就开始想代码,我想的是,中间一个人拿石头,那就可以监控两边的人啊,所以从第一个开始,一直向后……
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n,r,a[1010];
while(scanf("%d%d",&r,&n)==2&&n!=-1&&r!=-1)
{
for(int i=0; i<n; i++)
scanf("%d",&a[i]);
sort(a,a+n);
int sum=0,i=0;
while(i<n)
{
int x=a[i];
i++;
while(i<n && a[i]-x<=r) i++;//这个是判断距离0处有r的点,因为有个i++,所以i=过了r距离之后的第一个i
int p=a[i-1];//所以这个就是拿着石头的人
while(i<n && a[i]-p<=r) i++;//这个就是右边有r的距离
sum++;
}
printf("%d\n",sum);
}
return 0;
}
poj3069 Saruman's Army的更多相关文章
- POJ3069 Saruman's Army【贪心】
Saruman the White must lead his army along a straight path from Isengard to Helm's Deep. To keep tra ...
- poj3069 Saruman's Army(贪心)
https://vjudge.net/problem/POJ-3069 弄清楚一点,第一个stone的位置,考虑左右两边都要覆盖R,所以一般情况下不会在左边第一个(除非前两个相距>R). 一开始 ...
- Saruman's Army(POJ3069)
Description Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. ...
- 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(萨鲁曼军)
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 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 ...
- Saruman's Army(贪心)
Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep tra ...
随机推荐
- Html中Table的简单使用
虽然Table布局已经过时,偶尔还是会用到,简要实用代码,如下: <table border="1" cellpadding="0" cellspacin ...
- 关于datagridview里使用combox的总结
最近写的程序中需要在DataGridView中使用下拉选择的功能,首选方案是列的ColumnType属性 使用EditingControlShowing事件, if (e.Control is Com ...
- 【转】NGUI研究院之三种方式监听NGUI的事件方法(七)
NGUI事件的种类很多,比如点击.双击.拖动.滑动等等,他们处理事件的原理几乎万全一样,本文只用按钮来举例. 1.直接监听事件 把下面脚本直接绑定在按钮上,当按钮点击时就可以监听到,这种方法不太好很不 ...
- 修改XCode的Product的输出目录(有时不生效需看)
通常在情一般都不建议使用绝对路径,因为写死之后,换环境,换平台,又要重新修改路径,因此常常使用相对路径,哪么相对路径通常使用的就是环境变量了. 在Mac 中,xcode 中build settings ...
- h5移动版云胶片系统
h5移动版云胶片系统. 最近开了一个医疗用的云胶片,可以对图片放大.图片缩小,图片移动,图片调窗,图片切换,图片播放,图片变灰等等功能.如下图:
- docker 学习
vim /usr/lib/systemd/system/docker.service ExecStart=/usr/bin/docker daemon --bip=172.18.42.1/16 --r ...
- delphi 环境问题
这个编译时的警告该如何理解?[Warning] Unit 'Unit101' implicitly imported into package 'Package202'------解决方案------ ...
- 用Canvas制作简单的画图工具
今天用Canvas制作了一个画图工具,非常简单,功能也不是很多,主要有背景网格,画线,画圆,画矩形和画圆角矩形,也用到了canvas的一些基本知识,在这里一一列举. 1.线段的绘制: 如何绘制真正的1 ...
- kali 下文件操作
记得看到一片文章中说要学习linux 不要用kali.. 不感兴趣的东西,还指望我去搞个Ubuntu.... Ctrl+I 清屏 CD命令: cd 进入用户主目录: cd ~ 进入用户主目录: cd ...
- c#中按键小技巧
以后会补充其他的内容