Bzoj 3170 & Chebyshev distance

Source: Internet
Author: User

Test instructions

Given n points, select a point at this n point to make the other point tangent to the point of the Chebyshev distance and minimum.

SOL:

Tjoi really ... Kind or waterproof ... If you know what Chebyshev's distance is, that's not a stupid question. If you do not know that does not have to be crazy ...

Different from the random point of contact, this is selected with the X, Y axis or have a certain relationship. So we're going to do this like the smallest distance in the tree. And then ...

CODE:

  

/*==========================================================================# last modified:2016-03-04 19:52# filename:3170.cpp# Description: ==========================================================================*/# Define me Acrossthesky #include <cstdio> #include <cmath> #include <ctime> #include <string> #inc (in)  Lude <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <set> #include <map> #include <stack> #include <queue> #include <vector> #define LOWBIT (x) (x) & (-X ) #define for (I,A,B) for ((i) = (a);(i) <= (b);(i) + +) #define FORP (I,A,B) for (int i= (a); i<= (b); i++) #define FORM (i,a,b ) for (int i= (a); i>= (b); i--) #define LS (A, a) (((a) + (b)) << 1) #define RS (A, B) (((a) + (c)) >> 1) #define GETLC (a) ch[(a)][0] #define GETRC (a) ch[(a)][1] #define MAXN 130000 #define MAXM 130000 #define PI 3.1415926535898 #define _e 2.718281828459 #define INF 1070000000 using namespace Std typedef long Long LL;  typedef unsigned long long ull;     Template<class t> inline void read (t& num) {bool start=false,neg=false;     char c;     num=0;         while ((C=getchar ())!=eof) {if (c== '-') start=neg=true;             else if (c>= ' 0 ' && c<= ' 9 ') {start=true;         num=num*10+c-' 0 ';     } else if (start) break; } if (neg) num=-num; }/*==================split line==================*/struct infor{double x,y;int ID;} P[MAXN];d ouble ans[maxn];int cmpx (Infor a,infor b) {return a.x<b.x;} int Cmpy (Infor a,infor b) {return a.y<b.y;} int main () {int n; read (n); double sumx=0,sumy=0; Forp (i,1,n) {double x,y;scanf ("%lf%lf", &x,&y);p [i].x= (X+y)/2.0;p[i].y= (x-y)/2.0;p[i].id=i;sumx+=p[i].x; SUMY+=P[I].Y;} Sort (p+1,p+1+n,cmpx);d ouble temp=0; Forp (i,1,n) {//int t=p[i].x-p[i-1].x;ans[p[i].id]+= ((i-1) *p[i].x)-temp;ans[p[i].id]-= ((n-i+1) *p[i].x-(sumx-temp) ); temp+=p[i].x;} Sort (p+1,p+1+n,cmpy); temp=0; Forp (i,1,n) {ans[p[i].id]+= (i-1) *p[I].y-temp;ans[p[i].id]-= ((n-i+1) *p[i].y-(sumy-temp)); temp+=p[i].y;} Double out=ans[1]; Forp (i,1,n) out=min (out,ans[i]);p rintf ("%.0lf\n", Out);}

Bzoj 3170 & Chebyshev distance

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: info-contact@alibabacloud.com 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.