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
3
2 5 6 2 1.5
1.2 3 2 5 4
7 5 3 2 5
Sample Output
12.80
如果 横着枚举不行的话,我们就考虑竖着枚举。
1.
考虑, 去掉绝对值之后,你会发现最多 也就 中不同的状态,尽管 对于确定的, 只有一种状态,但是我们可以证明 正确的这种状态是 数值最大的。所以不用担心,错误的问题。
2.
拆开之后,会发现所有的状态都是 ,也就是说 对于一种确定的状态的话, 最大距离就是 同种状态下的最大值与最小值之差。
#include<cstdio>
#include<algorithm>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
const int maxn=1e5+10;
double val[maxn][5];
int main(){
int n;
scanf("%d",&n);
rep(i,0,n) rep(j,0,5)scanf("%lf",&val[i][j]);
double ans=0;
rep(j,0,32){
double mi=1e18,mx=-1e18;
rep(i,0,n){
double sum=0;
rep(k,0,5){
if(j&(1<<k))sum+=val[i][k];
else sum-=val[i][k];
}
mi=min(mi,sum);mx=max(mx,sum);
}
ans=max(ans,mx-mi);
}
printf("%.2f\n",ans);
return 0;
}