首页 > 代码库 > Rikka with Competition hdu 6095

Rikka with Competition hdu 6095

签到题目,排序然后按序清理掉一定会输的结果就可以。

ac代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[100001];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        int sum=0;
        scanf("%d %d",&n,&k);
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        sort(a,a+n);
        int vis[100001];
        memset(vis,0,sizeof(vis));
        sum=0;
        for(int j=n-1;j>=0;j--)
        {
            int temp=j-1;
            if(vis[j]) continue;
            while(a[j]-a[temp]>k && temp>=0)
            {
                sum++;
                vis[temp]=1;
                temp--;
            }
        }
        cout<<n-sum<<endl;
    }
    return 0;
}

 

Rikka with Competition hdu 6095