HDU 2523 sort (hash)

#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
  int t;
  int n,k;
  int x;
  int i;
  int a[2005],hash[2005];
  scanf("%d",&t);
  while(t--)
  {
      memset(a,0,sizeof(a));
      memset(hash,0,sizeof(hash));
      scanf("%d%d",&n,&k);
      for(int i=0;i<n;i++)
      {
          scanf("%d",&a[i]);
      }
      for(int i=0;i<n;i++)
      {
        for(int j=i+1;j<n;j++)
        {
            hash[abs(a[i]-a[j])]=1;
        }
      }
      
      for(int i=0,x=0; i<=2005&&x!=k; i++)
      {
          if(hash[i])
            x++;
            if(x==k)
                printf("%d
",i);
      }
     // printf("%d
",i-1);
  }
  return 0;
}

  

原文地址:https://www.cnblogs.com/Roni-i/p/7216376.html