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