https://vjudge.net/problem/POJ-3069

弄清楚一点,第一个stone的位置,考虑左右两边都要覆盖R,所以一般情况下不会在左边第一个(除非前两个相距>R)。

一开始二层循环外层写的i=1,这样对于数据诸如1 1 1=>0,而其实结果是1.

 #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
int R, n, a[];
int main()
{
while(cin >> R >> n){
if(R == -&&n == -) break;
for(int i = ; i < n; i++){
cin >> a[i];
}
sort(a, a+n);
int flag=;
int st = , ans=;//st表示第一个未被覆盖的点
for(int i = ; i < n;){//一开始这里写的i=0,WA了
while(i < n&&a[i]-a[st]<=R){
i++;
}
int t = i-;//此处放一个
ans++;
while(i < n&&a[i]-a[t]<=R){
i++;
}
st = i;
}
cout << ans << endl;
}
return ;
}

poj3069 Saruman's Army(贪心)的更多相关文章

  1. POJ3069 Saruman's Army【贪心】

    Saruman the White must lead his army along a straight path from Isengard to Helm's Deep. To keep tra ...

  2. POJ 3617 Best Cow Line ||POJ 3069 Saruman's Army贪心

    带来两题贪心算法的题. 1.给定长度为N的字符串S,要构造一个长度为N的字符串T.起初,T是一个空串,随后反复进行下面两个操作:1.从S的头部删除一个字符,加到T的尾部.2.从S的尾部删除一个字符,加 ...

  3. poj3069 Saruman's Army

    http://poj.org/problem?id=3069 Saruman the White must lead his army along a straight path from Iseng ...

  4. POJ 3069 Saruman's Army(贪心)

     Saruman's Army Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  5. poj 3069 Saruman's Army 贪心模拟

    Saruman's Army Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18794   Accepted: 9222 D ...

  6. B - B Saruman's Army(贪心)

    在一条直线上,有n个点.从这n个点中选择若干个,给他们加上标记.对于每一个点,其距离为R以内的区域里必须有一个被标记的点.问至少要有多少点被加上标记 Saruman the White must le ...

  7. poj 3069 Saruman's Army 贪心 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=3069 题解 题目可以考虑贪心 尽可能的根据题意选择靠右边的点 注意 开始无标记点 寻找左侧第一个没覆盖的点 再来推算既可能靠右的标记点为一 ...

  8. Saruman's Army(贪心)

    Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. To keep tra ...

  9. Saruman's Army(POJ3069)

    Description Saruman the White must lead his army along a straight path from Isengard to Helm’s Deep. ...

随机推荐

  1. update + join 多表操作

    UPDATE vtiger_notificationcf as a INNER JOIN vtiger_crmentity as b ON a.notificationid = b.crmid SET ...

  2. Codeforces 639D Bear and Contribution

    Bear and Contribution 对于对于5余数为, 0, 1, 2, 3, 4的分别处理一次, 用优先队列贪心. #include<bits/stdc++.h> #define ...

  3. jquery的div局部刷新

    jquery的div局部刷新 //div的局部刷新 $(".dl").load(location.href+" .dl"); 全页面的刷新方法 window.l ...

  4. 51Nod1253 Kundu and Tree 容斥原理

    原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1253.html 题目传送门 - 51Nod1253 题意 树包含 N 个点和 N-1 条边.树的边有 ...

  5. Java中文字符所占的字节数

    Java语言中,中文字符所占的字节数取决于字符的编码方式,一般情况下,采用ISO8859-1编码方式时,一个中文字符与一个英文字符一样只占1个字节:采用GB2312或GBK编码方式时,一个中文字符占2 ...

  6. POJ 1979 红与黑

    题目地址: http://poj.org/problem?id=1979  或者  https://vjudge.net/problem/OpenJ_Bailian-2816 Red and Blac ...

  7. PyQt PySide QListWidget 添加自定义 widget

    PyQt PySide QListWidget 添加自定义 widget 原文链接:https://stackoverflow.com/questions/25187444/pyqt-qlistwid ...

  8. POJ 2481 Cows 【树状数组】

    <题目链接> 题目大意: 就是给出N个区间,问这个区间是多少个区间的真子集. 解题分析: 本题与stars类似,只要巧妙的将线段的起点和终点分别看成 二维坐标系中的x,y坐标,就会发现,其 ...

  9. 色彩空间-- RGB\HSV

    颜色空间 标签(空格分隔): 计算机视觉 颜色通常用三个独立的属性来描述,三个独立变量综合作用,自然就构成一个空间坐标,这就是颜色空间. RGB和CMY颜色模型都是面向硬件的,而HSV(Hue Sat ...

  10. 服务端线程模型-NIO服务模型

    上接<服务端线程模型-线程池服务模型>(https://www.cnblogs.com/fudashi233/p/10549221.html). 这篇分享从最初的单线程服务模型一直演进到线 ...