Title: A city of vertical streets, inhabited by many friends (houses are at intersections);
Now they want to have a party and ask where to run the path and the smallest that can make everyone walk.
Analysis: Median. The distance in the subject is the Hamiltonian distance dist (<x1,y2>,<x2,y2>) = |x1-x2|+|y1-y2|.
The location is set at <x,y> sumdist = SUM (|x-xi|+|y-yi|) = SUM (|x-xi|) +sum (Y-yi);
For the minimum value of the σ|x-xi|, take the median of Xi, i.e. x = X[n/2], and the same as Y = y[n/2].
Description: Rushed into the UVa450 ╮(╯▽╰)╭.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio>using namespace Std;int x[50005];int y[50005];int main () {int t,s,a,f;while (~scanf ("%d", &t)) while (T--) { scanf ("%d%d%d", &s,&a,&f); for (int i = 0; i < F; + + i) scanf ("%d%d", &x[i],&y[i]); sort (x, x+f); Sort ( Y, Y+f);p rintf ("(Street:%d, Avenue:%d) \ n", x[(F-1)/2], y[(f-1)/2]);} return 0;}
UVa 855-lunch in Grid City