Problem Description
Give you N integers, x1,x2...xn, any combination of two integers to get |xi-xj|, (0 < I,j<=n,i!=j).
Now please calculate the number of K-large combinations (a combination of the number of K-large refers to having K-1 a different number of combinations less than it).
Input
The input data first contains a positive integer c, which indicates that a C group of test cases is included.
The first row of each set of test data contains two integer n,k. (1< n<=1000,0< k<=2000)
The next line contains n integers, representing x1,x2. Xn (0<=xi<=2000)
Output
For each set of test data, output a number of K-large combinations, one row per output instance.
Sample Input
3
3 2
4 0 7
4 2
1 2 3 4
2 1
2 9
Sample Output
4
2
7
Test instructions very simple ~
is to ask for the K combination number (the number of combinations from small to the same, the repetition count only once)
It is easy to know that the number of n number of combinations of the maximum is n (n-1)/2, there may be duplicate, put this n (n-1)/2 combination number with the array storage, according to small to large order, and then from small to large to find out the number of K non-repetition!!!
Import Java.util.arrays;import Java.util.Scanner; Public classMain { Public Static void Main(string[] args) {Scanner SC =NewScanner (System.inch);intT =sc.nextint (); while(t-->0){intn =sc.nextint ();intK=sc.nextint ();intA[] =New int[n]; for(intI=0; i<n;i++) {a[i]=sc.nextint (); } arrays.sort (a);intB[] =New int[N (n1)/2];intH=0; for(intI=0; i<n-1; i++) { for(intj=i+1; j<n;j++) {b[h]=math.abs (a[i]-a[j])); h++; }} arrays.sort (b); H=0; for(intI=0; i<b.length-1; i++) {if(b[i]!=b[i+1]) {h++;if(h==k) {h=i; Break; }}} System. out. println (B[h]); } }}
Hdoj (HDU) 2523 sort AGAIN (derivation sort,,)