Hangzhou Computer Program Design Competition (2016 ' 12)-Network synchronization 1007

Source: Internet
Author: User

Contrast Moe

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 0 Accepted Submission (s): 0

Problem description has 2N individuals, each with an Moe mi (1<=i<=2n).
They are required to be divided into n pairs, so that the sum of the contrast values is maximal.
The meaning of the contrast value is as follows: if x and Y are a pair, they contribute | mx-my| point contrast value. The first line of input is a number T, which indicates the number of test instances.
followed by the T-line, the first number of n per line, then the 2N individual's Moe mi.
1<=t<=10
1<=n<=1000
-1000<=mi<=1000
All input numbers are integers. Output for each set of instances, export the maximum value of the sum of the contrast values, one row per test instance. Sample Input21 13 142 1-2 0 3 Sample Output16 Solution: Sort + END Add
#include <bits/stdc++.h>using namespacestd;intMain () {intT; CIN>>T;  while(t--)    {        inta[10000]; intN; CIN>>N;  for(intI=1; i<=2*n;i++) {cin>>A[i]; }        intsum=0; Sort (a+1, A +1+2*N);  for(intI=1; i<=n;i++) {sum+ = (ABS (a[i]-a[2*n-i+1])); } cout<<sum<<Endl; }    return 0;}

Hangzhou Computer Program Design Competition (2016 ' 12)-Network synchronization 1007

Related Article

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.