P3382: [Usaco2004 Open]cave cows 3 The three cows in the cave

Source: Internet
Author: User

First, let's make sure that the longest Manhattan distance is only possible for x1+y2-(X2+y2) and x1-y1-(x2-y2) so we only need to maintain four values,

Represents Max (X+y), respectively; Max (x-y); Min (x+y); Min (x-y);

So the answer is Max (max (x+y)-min (x+y), Max (x-y)-min (x-y).

1 Constmaxn=3000000;2 varMaxadd,minadd,maxdec,mindec,i,a,b,n:longint;3 function Max (a,b:longint): Longint;4 begin5   ifA>B then exit (a)6     Elseexit (b);7 end;8 function min (a,b:longint): Longint;9 beginTen   ifa<B then exit (a) One     Elseexit (b); A end; - begin -MINADD:=MAXN; mindec:=MAXN; the READLN (n); -    fori:=1to n Do - begin - Readln (A, b); +Maxadd:=max (maxadd,a+b); -Minadd:=min (minadd,a+b); +Maxdec:=max (maxdec,a-b); AMindec:=min (mindec,a-b); at end; -Writeln (Max (maxadd-minadd,maxdec-mindec)); -End.
View Code

(Reproduced Please specify Source: http://www.cnblogs.com/Kalenda/)

P3382: [Usaco2004 Open]cave cows 3 The three cows in the cave

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.