HDU2523 SORT AGAIN

http://acm.hdu.edu.cn/showproblem.php?pid=2523

随手练习

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int B[12345];
 4 int main(){
 5    int t;
 6    scanf("%d",&t);
 7    while(t--){
 8     memset(B,0,sizeof(B));
 9     int n,k;
10     int A[1234];
11     scanf("%d%d",&n,&k);
12     for(int i=1;i<=n;i++){
13         scanf("%d",&A[i]);
14     }
15     for(int i=1;i<=n;i++){
16         for(int j=i+1;j<=n;j++){
17             int x=fabs(A[i]-A[j]);
18             B[x]=1;
19         }
20     }
21     for(int i=0;i<=2000;i++){
22         if(B[i]==1){
23             k--;
24         }
25         if(k==0){
26             cout<<i<<endl;
27             break;
28         }
29     }
30    }
31    return 0;
32 }
原文地址:https://www.cnblogs.com/yinghualuowu/p/7486356.html