码迷,mamicode.com
首页 > 其他好文 > 详细

Rikka with Competition hdu 6095

时间:2017-08-08 21:44:18      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:turn   space   names   iostream   algorithm   题目   com   end   clu   

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

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

标签:turn   space   names   iostream   algorithm   题目   com   end   clu   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!