哈希表..球阀
代码:
#include<iostream>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
bool hash[2000];
int main()
{
    int c,n,k,i,j;
    scanf("%d",&c);
    while(c--)
    {
      scanf("%d%d",&n,&k);
      memset(hash,0,sizeof(hash));
      vector<int>sav(n);
      for(i=0;i<n;i++) 
          scanf("%d",&sav[i]);
       sort(sav.begin(),sav.end(),less<int>());
       for(i=0;i<n;i++)
       {
           for(j=i+1;j<n ;j++)
           {
              hash[sav[j]-sav[i]]=true;
           }
       }
       for(i=0;i<=2000&&k>0;i++)
       {
           if(hash[i])   k--;
       }
       printf("%d\n",i-1);
    }
    return 0;
}

想到过很多方法,都超时了,看了别人的代码,才发现,有这么一出,居然没想到...爱,菜鸟,终究是菜鸟...

相关文章:

  • 2021-09-26
  • 2021-08-28
  • 2021-10-24
  • 2021-11-03
  • 2021-09-17
  • 2021-06-28
  • 2021-06-28
  • 2021-11-21
猜你喜欢
  • 2022-01-20
  • 2022-12-23
  • 2021-12-22
  • 2021-11-18
  • 2021-07-20
  • 2021-11-15
  • 2022-01-24
相关资源
相似解决方案