Test instructions
The "distance" sum of any two points for n points:
The "distance" definition for A, B is: Min (|ax-bx|,|ay-by|) (n<200000)
Good question!
Analytical:
Look, no idea.
First formulation Jane: let Ax=sx+sy;
Ay=sx-sy;
Bx=tx+ty;
By=tx-ty;
Thereupon: Min (|ax-bx|,|ay-by|) =min (Ax-bx,bx-ax,ay-by,by-ay) =min (Sx-tx+sy-ty,tx-sx+ty-sy,sx-tx+sy-ty,tx-sx+ty-sy);
=|sx-tx|+|sy-ty|
Here's the obvious:
sx= (Ax+ay)/2 sy= (Ax-ay)/2
So they were sorted by Sx,sy;
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstdlib>5#include <algorithm>6#include <cstring>7#include <vector>8 9 #definell Long LongTen #defineN 222222 One A ll A[n],b[n]; - using namespacestd; - the intMain () - { - intT; -scanf"%d",&T); + while(t--) - { + intn,c,d; Ascanf"%d%d%d",&n,&c,&d); at for(intI=1; i<=n;i++) - { - intx, y; -scanf"%d%d",&x,&y); -a[i]= (LL) c*x+d*y; -b[i]= (LL) c*x-d*y; in } - toSort (A +1, a+n+1); +Sort (b +1, b+n+1); - thell ans=0; *ll ans1=0; $ for(intI=1; i<=n;i++)Panax Notoginseng { -ans1+=A[i]; theans+=a[i]*i-ans1; + } Aans1=0; the for(intI=1; i<=n;i++) + { -ans1+=B[i]; $ans+=b[i]*i-ans1; $ } -printf"%lld\n",ans>>1); - } the return 0; -}
View Code
Codechef Taxi Driver