首页 > 其他 > 详细

Rikka with Competition hdu 6095

时间:2017-08-08 21:15:09      阅读:224      评论:0      收藏:0      [点我收藏+]

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

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

原文:http://www.cnblogs.com/z1141000271/p/7308846.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!