UVa 10041

From Algorithmist
Jump to: navigation, search

Contents

[edit] 10041 - Vito's Family

[edit] Summary

1D Geometric Median

[edit] Explanation

O(n2) brute force solution clocks at about 0.080s.
O(nlogn + n) solution where we sort the input and determine the sum of distance from each of the locations clocks at about 0.030s.
Another O(nlogn + n) solution is to sort the input array and determine the distance from median to all.

[edit] Input

2
2 2 4
3 2 4 6

[edit] Output

2
4

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox