Saruman's Army

版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/45845115

Saruman's Army

#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX_N 2000

int N,R;
int X[MAX_N];

void solve()
{
    sort(X,X+N);
    int i=0,ans=0;
    while(i<N)
    {
        int s=X[i++];
        while(i<N&&X[i]<=s+R)
            i++;
        int p=X[i-1];
        while(i<N&&X[i]<=p+R)
            i++;
        ans++;
    }
    printf("%d\n",ans);
}

int main()
{
    printf("N R:\n");
    scanf("%d %d",&N,&R);

    printf("X[%d]:\n",N);
    for(int i=0;i<N;i++)
    {
        scanf("%d",&X[i]);
    }

    solve();
    return 0;
}
上一篇:puppet自动化技术基础分析及实例部署详解


下一篇:FPGA设计中遇到的奇葩问题之“芯片也要看出身”(一)