POJ3224 Go for Lab cup!

Source: Internet
Author: User

Water problem, but the topic content is difficult to read, add up again can. Optimal Parking
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7579 Accepted: 4555

Description

When shopping on Long Street, Michael usually parks his car at some random location, and then walks to the stores he needs . Can you help Michael choose a place to park which minimises the distance he needs to walk on his shopping round? Long Street is a straight line, where all positions is integer. The parking in a specific slot, which are an integer position on Long Street. Michael does not want to pay for more than one parking though. He is very strong, and does don't mind carrying all the bags around.

Input

The first line of input gives the number of test cases, 1≤ T ≤100. There is and lines for each test case. The first gives the number of stores Michael wants to visit, 1≤ n ≤20, and the second gives theirn int Eger positions on Long Street, 0≤ XI ≤99.

Output

Output for each test case a line with the minimal distance Michael must walk given optimal parking.

Sample Input

2424 13 89 3767 30 41 14 39 42

Sample Output

15270

Source

Nordic 2007
1 //Oimonster2#include <cstdio>3#include <cstdlib>4#include <iostream>5 using namespacestd;6 inta[101][101],s[101];7 intMain () {8     intI,j,n;9scanf"%d",&n);Ten      for(i=1; i<=n;i++) One          for(j=1; j<=n;j++){ Ascanf"%d",&a[i][j]); -s[i]+=A[i][j]; -s[j]+=5-A[i][j]; the         } -     intMax,ans; -max=ans=0; -      for(i=1; i<=n;i++){ +         if(s[i]>max) { -max=S[i]; +cn1=i; A         } at     } -printf"%d\n", ans); -     return 0; -}
View Code

POJ3224 Go for Lab cup!

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.