POJ 3069 Saruman's Army 贪心
来源:互联网 发布:linux查看文件类型 编辑:程序博客网 时间:2024/05/16 08:08
Description
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 310 20 2010 770 30 1 7 15 20 50-1 -1
Sample Output
24
Hint
In the first test case, Saruman may place a palantir at positions 10 and 20. Here, note that a single palantir with range 0 can cover both of the troops at position 20.
In the second test case, Saruman can place palantirs at position 7 (covering troops at 1, 7, and 15), position 20 (covering positions 20 and 30), position 50, and position 70. Here, note that palantirs must be distributed among troops and are not allowed to “free float.” Thus, Saruman cannot place a palantir at position 60 to cover the troops at positions 50 and 70.
Source
[Submit] [Go Back] [Status] [Discuss]
抽象成一维数轴上的若干个点,标记一个点那么这个点可以辐射到len范围(左右都可以)距离内的点。给出点的影响范围len问如何标记最少的点使得全部的点都被辐射到。
先从最左边的点找到离它最远且能辐射到它的点,然后找到这个点能影响到的最右边的点,这样就找的了一个点然后类推。
ACcode:
#pragma warning(disable:4786)//使命名长度不受限制#pragma comment(linker, "/STACK:102400000,102400000")//手工开栈#include <map>#include <set>#include <queue>#include <cmath>#include <stack>#include <cctype>#include <cstdio>#include <cstring>#include <stdlib.h>#include <iostream>#include <algorithm>#define rd(x) scanf("%d",&x)#define rd2(x,y) scanf("%d%d",&x,&y)#define rds(x) scanf("%s",x)#define rdc(x) scanf("%c",&x)#define ll long long int#define maxn 100005#define mod 1000000007#define INF 0x3f3f3f3f //int 最大值#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)#define MT(x,i) memset(x,i,sizeof(x))#define PI acos(-1.0)#define E exp(1)using namespace std;int len,n,cnt,st,ed;int a[maxn];int main(){ while(rd2(len,n)&&(len+n!=-2)){ FOR(i,1,n)rd(a[i]); sort(a+1,a+1+n);cnt=0; FOR(i,1,n){ st=a[i]; while(i<=n&&a[i]<=st+len)i++; ed=a[i-1]; while(i<=n&&a[i]<=ed+len)i++; i--; cnt++; } printf("%d\n",cnt); } return 0;}
- poj 3069 Saruman's Army 贪心
- poj 3069Saruman's Army 贪心
- poj 3069 Saruman's Army(贪心)
- POJ 3069 Saruman's Army (贪心)
- POJ 3069 : Saruman\'s Army - 贪心
- POJ 3069 Saruman's Army (贪心)
- POJ 3069 - Saruman's Army(贪心)
- POJ 3069 Saruman's Army (贪心)
- POJ 3069 Saruman's Army(贪心)
- POJ 3069 Saruman's Army (简单贪心)
- POJ 3069 Saruman's Army(贪心)
- POJ 3069 Saruman's Army (贪心 )
- POJ - 3069 Saruman's Army(贪心)
- Poj 3069 Saruman's Army【贪心】
- poj 3069 Saruman's Army 【贪心】
- POJ 3069 Saruman's Army 贪心
- POJ 3069 Saruman's Army(贪心)
- POJ 3069 Saruman's Army(贪心)
- 使用PL/SQL连接本地oracle时报错:ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务解决
- [JS][技巧]利用事件冒泡特性处理多个按钮的单击事件
- 卡方检验文本特征选择
- Python BeautifulSoup 实战演练
- 【FastDev4Android框架开发】AndroidAnnnotations注入框架使用之注入组件Components(九)
- POJ 3069 Saruman's Army 贪心
- IO类
- 简单servlet 监听
- 关于arXive的一点了解
- Apriori算法
- Edge水流向题(Problem ID:1033)
- android:scaleType属性
- 5.7 Pairwise Swap
- libcef学习最详细的入门资料系列之二 :libcef的编译和运行,以及MFC下的实现