Codechef Taxi Driver

Source: Internet
Author: User

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!


Look, no idea.

First formulation Jane: let Ax=sx+sy;




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


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

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