Hdoj (HDU) 2523 sort AGAIN (derivation sort,,)

Source: Internet
Author: User

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,,)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.