vijos-p1691-oil pipeline problem (Java + big watermelon ...) )

Source: Internet
Author: User

P1691Oil pipeline problem accepted Tags: greedy other sort<textarea id="code" class="textbox" style=""></textarea>Background

Miss Car Gf,car out of the water problem!

Describe

An oil company plans to build a main oil pipeline from east to west. The pipe is going through an oil field with N Wells. A pipeline along the shortest route (or South or north) is connected to the main road from each well. Given the position of n wells, i.e. their x-coordinate (east-west) and y-coordinate (north-south direction), how to determine the optimal position of the main road, even if the oil wells to the main road between the length of the pipeline is the smallest sum of position?

Programming tasks:
Given the position of the N-Port well, the sum of the minimum length of the oil pipeline between the wells and the main road is programmed.

Format input Format

The input data is provided by the file Input.txt.

The 1th line of the file is the number of Wells n,1≤n≤10000.

The next n rows are the position of the well, with 2 integers x and y,-10000≤x,y≤10000 per row.

Output format

When the program runs at the end, output the calculation to the file output.txt. The number in line 1th of the file is the sum of the minimum length of the oil pipeline between the wells and the main road.

Example 1 sample input 1[copy]
51 22 21 3 3-23 3
Sample output 1[Copy]
6
Limit

Each test point 1s

Tips

Each test point 1s

Source

Classic Algorithms


Always eat watermelon drink farmers Spring is not the way ah ...


Import Java.io.*;import java.util.*;p ublic class main{public static void Main (string[] args) {//TODO auto-generated Metho D stubscanner input = new Scanner (system.in); int n = input.nextint (); int a[] = new Int[n];for (int i = 0; i < n; i++) {i Nput.nextint (); A[i] = Input.nextint ();} Arrays.sort (a); int ans = 0;for (int i = 0; i < n; i++) {ans + = Math.Abs (A[i]-A[N/2]);} System.out.println (ANS);}}




vijos-p1691-oil pipeline problem (Java + big watermelon ...) )

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.