POJ 2926 Requirements (空间最远曼哈顿距离)

网友投稿 754 2022-08-26

POJ 2926 Requirements (空间最远曼哈顿距离)

POJ 2926 Requirements (空间最远曼哈顿距离)

Description

An undergraduate student, realizing that he needs to do research to improve his chances of being accepted to graduate school, decided that it is now time to do some independent research. Of course, he has decided to do research in the most important domain: the requirements he must fulfill to graduate from his undergraduate university. First, he discovered (to his surprise) that he has to fulfill 5 distinct requirements: the general institute requirement, the writing requirement, the science requirement, the foreign-language requirement, and the field-of-specialization requirement. Formally, a requirement is a fixed number of classes that he has to take during his undergraduate years. Thus, for example, the foreign language requirement specifies that the student has to take 4 classes to fulfill this requirement: French I, French II, French III, and French IV. Having analyzed the immense multitude of the classes that need to be taken to fulfill the different requirements, our student became a little depressed about his undergraduate university: there are so many classes to take…Dejected, the student began studying the requirements of other universities that he might have chosen after high school. He found that, in fact, other universities had exactly the same 5 requirements as his own university. The only difference was that different universities had different number of classes to be satisfied in each of the five requirement.Still, it appeared that universities have pretty similar requirements (all of them require a lot of classes), so he hypothesized that no two universities are very dissimilar in their requirements. He defined the dissimilarity of two universities X and Y as |x1 − y1| + |x2 − y2| + |x3 − y3| + |x4 − y4| + |x5 − y5|, where an xi (yi) is the number of classes in the requirement i of university X (Y) multiplied by an appropriate factor that measures hardness of the corresponding requirement at the corresponding university.

Input

The first line of the input file contains an integer N (1 ≤ N ≤ 100 000), the number of considered universities. The following N lines each describe the requirements of a university. A university X is described by the five non-negative real numbers x1 x2 x3 x4 x5.

Output

On a single line, print the dissimilarity value of the two most dissimilar universities. Your answer should be rounded to exactly two decimal places.

Sample Input

32 5 6 2 1.51.2 3 2 5 47 5 3 2 5

Sample Output

12.80

题意

给出五维空间 ​​N​​ 个点的坐标,求其中两点的最大曼哈顿距离。

思路

我们可以定义曼哈顿距离的正式意义为L1-距离或城市区块距离,也就是在欧几里得空间的固定直角坐标系上两点所形成的线段对轴产生的投影的距离总和。

例如在平面上,坐标 (x1,y1) 的点 P1 与坐标 (x2,y2) 的点 P2 的曼哈顿距离为: |x1−x2|+|y1−y2|

在二维平面中,设距离最远的两点坐标为 (a1,b1) (a2,b2) 则其曼哈顿距离为: |a1−a2|+|b1−b2|

去掉绝对值便有四种形式:

(a1−a2)+(b1−b2)(a1−a2)+(b2−b1)(a2−a1)+(b1−b2)(a2−a1)+(b2−b1)

可以对上面的式子变形整理一下转化为:

(a1+b1)−(a2+b2)(a1−b1)−(a2−b2)(−a1+b1)−(−a2+b2)(−a1−b1)−(−a2−b2)

我们发现每一项对应坐标的符号都相同,于是可以假设 ​​1​​​ 代表正号, ​​0​​​ 代表负号,于是 (a1+b1) 可以表示为 ​​11​​ 。

要表示空间中所有状态,只需要用 ​​0~1<

于是对所有的点,求出上面的那四种转化过的形式,记录每种状态的最小值与最大值,枚举找最大差值即可。

AC 代码

#include #include#include#include#include#includeusing namespace std;const double INF = 1e200;const int d=5;double a[d];double maxx[1<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:HDU 4622 Reincarnation (区间不相同子串个数:字符串哈希 | 后缀数组 | 后缀自动机)
下一篇:UPC 1017 Easy Tree Query (二叉搜索树)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~