Requirements
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 3908   Accepted: 1318

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 Xand 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

Source

 
  最远曼哈顿距离
  不算完全的计算几何类型的题,主要是曼哈顿距离的知识。
  代码很笨重,但是能做出来,改天再优化。(已优化,见下
 
  整理出的求最大曼哈顿距离模板
#define inf 1e200
double a[][]; //每一个点的5个坐标值
double GetManhattan(double p[][],int n,int dem)
{
double ans = ,Min,Max;
int i,j,k;
for(i=;i<(<<(dem-1));i++){ //用二进制形式遍历所有可能的运算情况
Min = inf,Max = -inf;
for(j=;j<n;j++){ //遍历每一个点
double sum = ;
for(k=;k<;k++){ //因为是五维的,所以有4个运算符
//提取当前运算符
int t = i & <<k; //1为+,0为-
if(t) sum+=p[j][k];
else sum-=p[j][k];
}
if(sum>Max) Max = sum;
if(sum<Min) Min = sum;
}
if(Max-Min>ans)
ans = Max - Min;
}
return ans;
}
  
  代码:
 #include<iostream>
#include<stdio.h>
#include<iomanip>
const double MAX=1e100;
const double MIN=-1e100;
using namespace std;
int n;
double fivemaxdistance() //三维点集最大曼哈顿距离
{
double max1=MIN,min1=MAX,max2=MIN,min2=MAX,max3=MIN,min3=MAX,max4=MIN,min4=MAX,
max5=MIN,min5=MAX,
max6=MIN,min6=MAX,
max7=MIN,min7=MAX,
max8=MIN,min8=MAX,
max9=MIN,min9=MAX,
max10=MIN,min10=MAX,
max11=MIN,min11=MAX,
max12=MIN,min12=MAX,
max13=MIN,min13=MAX,
max14=MIN,min14=MAX,
max15=MIN,min15=MAX,
max16=MIN,min16=MAX,x,y,z,k,l,ans;
for(int i=;i<=n;++i)
{
scanf("%lf%lf%lf%lf%lf",&x,&y,&z,&k,&l);
if(x+y+z+k+l>max1) max1=x+y+z+k+l;
if(x+y+z+k+l<min1) min1=x+y+z+k+l;
if(x-y+z+k+l>max2) max2=x-y+z+k+l;
if(x-y+z+k+l<min2) min2=x-y+z+k+l;
if(x+y-z+k+l>max3) max3=x+y-z+k+l;
if(x+y-z+k+l<min3) min3=x+y-z+k+l;
if(x+y+z-k+l>max4) max4=x+y+z-k+l;
if(x+y+z-k+l<min4) min4=x+y+z-k+l;
if(x+y+z+k-l>max5) max5=x+y+z+k-l;
if(x+y+z+k-l<min5) min5=x+y+z+k-l;
if(x-y-z+k+l>max6) max6=x-y-z+k+l;
if(x-y-z+k+l<min6) min6=x-y-z+k+l;
if(x-y+z-k+l>max7) max7=x-y+z-k+l;
if(x-y+z-k+l<min7) min7=x-y+z-k+l;
if(x-y+z+k-l>max8) max8=x-y+z+k-l;
if(x-y+z+k-l<min8) min8=x-y+z+k-l;
if(x+y-z-k+l>max9) max9=x+y-z-k+l;
if(x+y-z-k+l<min9) min9=x+y-z-k+l;
if(x+y-z+k-l>max10) max10=x+y-z+k-l;
if(x+y-z+k-l<min10) min10=x+y-z+k-l;
if(x+y+z-k-l>max11) max11=x+y+z-k-l;
if(x+y+z-k-l<min11) min11=x+y+z-k-l;
if(x-y-z-k+l>max12) max12=x-y-z-k+l;
if(x-y-z-k+l<min12) min12=x-y-z-k+l;
if(x+y-z-k-l>max13) max13=x+y-z-k-l;
if(x+y-z-k-l<min13) min13=x+y-z-k-l;
if(x-y+z-k-l>max14) max14=x-y+z-k-l;
if(x-y+z-k-l<min14) min14=x-y+z-k-l;
if(x-y-z+k-l>max15) max15=x-y-z+k-l;
if(x-y-z+k-l<min15) min15=x-y-z+k-l;
if(x-y-z-k-l>max16) max16=x-y-z-k-l;
if(x-y-z-k-l<min16) min16=x-y-z-k-l;
}
ans=max1-min1;
if(max2-min2>ans) ans=max2-min2;
if(max3-min3>ans) ans=max3-min3;
if(max4-min4>ans) ans=max4-min4;
if(max5-min5>ans) ans=max5-min5;
if(max6-min6>ans) ans=max6-min6;
if(max7-min7>ans) ans=max7-min7;
if(max8-min8>ans) ans=max8-min8;
if(max9-min9>ans) ans=max9-min9;
if(max10-min10>ans) ans=max10-min10;
if(max11-min11>ans) ans=max11-min11;
if(max12-min12>ans) ans=max12-min12;
if(max13-min13>ans) ans=max13-min13;
if(max14-min14>ans) ans=max14-min14;
if(max15-min15>ans) ans=max15-min15;
if(max16-min16>ans) ans=max16-min16;
return ans;
}
int main()
{
while(cin>>n)
{ //输入点数
cout<<setiosflags(ios::fixed)<<setprecision();
cout<<fivemaxdistance()<<endl;
}
return ;
}

  优化方法(用二进制方法遍历运算符)

 #include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std; #define inf 1e200
double a[][]; //每一个点的5个坐标值
double GetManhattan(double p[][],int n,int dem)
{
double ans = ,Min,Max;
int i,j,k;
for(i=;i<(<<(dem-1));i++){ //用二进制形式遍历所有可能的运算情况
Min = inf,Max = -inf;
for(j=;j<n;j++){ //遍历每一个点
double sum = ;
for(k=;k<;k++){ //因为是五维的,所以有4个运算符
//提取当前运算符
int t = i & <<k; //1为+,0为-
if(t) sum+=p[j][k];
else sum-=p[j][k];
}
if(sum>Max) Max = sum;
if(sum<Min) Min = sum;
}
if(Max-Min>ans)
ans = Max - Min;
}
return ans;
}
int main()
{
int i,j,n;
while(cin>>n){
for(i=;i<n;i++) //输入n个点
for(j=;j<;j++)
scanf("%lf",&a[i][j]);
//计算最短曼哈顿距离
cout<<setiosflags(ios::fixed)<<setprecision();
cout<<GetManhattan(a,n,)<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

poj 2926:Requirements(最远曼哈顿距离,入门题)的更多相关文章

  1. POJ-2926 Requirements 最远曼哈顿距离

    题目链接:http://poj.org/problem?id=2926 题意:求5维空间的点集中的最远曼哈顿距离.. 降维处理,推荐2009武森<浅谈信息学竞赛中的“0”和“1”>以及&l ...

  2. hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  3. HDU 4666 Hyperspace (最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  4. poj 2926 Requirements

    点击打开poj 2926 思路: n维空间计算最远的曼哈顿距离 分析: 1 题目给定n个5维的点,要求最远的曼哈顿距离 2 求最远曼哈顿距离,对于一个n维的空间,其中两点的曼哈顿距离为:|x1-x2| ...

  5. HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  6. 【POJ 3241】Object Clustering 曼哈顿距离最小生成树

    http://poj.org/problem?id=3241 曼哈顿距离最小生成树模板题. 核心思想是把坐标系转3次,以及以横坐标为第一关键字,纵坐标为第二关键字排序后,从后往前扫.扫完一个点就把它插 ...

  7. [HDU 4666]Hyperspace[最远曼哈顿距离][STL]

    题意: 许多 k 维点, 求这些点之间的最远曼哈顿距离. 并且有 q 次操作, 插入一个点或者删除一个点. 每次操作之后均输出结果. 思路: 用"疑似绝对值"的思想, 维护每种状态 ...

  8. HDU 4666 最远曼哈顿距离

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4666 关于最远曼哈顿距离的介绍: http://blog.csdn.net/taozifish/ar ...

  9. 2018 Multi-University Training Contest 10 CSGO(HDU - 6435)(最远曼哈顿距离)

    有 n 种主武器,m 种副武器.每种武器有一个基础分数k种属性值 X[i] . 选出一种主武器 mw 和一种副武器 sw,使得两种武器的分数和 + 每个属性的差值尽量大.(参考下面的式子) 多维的最远 ...

随机推荐

  1. iOS欢迎界面Launch Screen动态加载广告

    有许多应用程序在打开的时候,欢迎界面会加载一张连网获取的广告图片或者显示一组动画,这样的效果是如何做到的呢?下面给大家介绍一种简单的实现加载广告的方式. 程序运行起来,欢迎界面之后,会进入AppDel ...

  2. How can I style a JavaFX SplitMenuButton in CSS

    0 down vote favorite I try to style a SplitMenuButton in JavaFX. I've got a menuButton and a SplitMe ...

  3. Substance风格实例大全javaswing皮肤风格大全(原)

    转载请注明来路:http://www.cnblogs.com/langtianya/ 下图是所支持的设置 下面把上面的每一个选项的子选项进行试验 substance皮肤: AutumnSkin Bus ...

  4. vs2012 智能提示消失解决办法

    一般你可以重启vs就可以解决问题,最蛋疼的是你重启也没用.只能重置,再不行就重装vs,再不行你就重装系统......扯淡了... 重置Visual Studio可以解决此问题, 方法:开始->M ...

  5. PHP雪花背景验证码

    ValidateCode.class.php 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ...

  6. Power Network(网络流最大流 & dinic算法 + 优化)

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24019   Accepted: 12540 D ...

  7. LVS负载均衡集群服务搭建详解(二)

    lvs-nat模型构建 1.lvs-nat模型示意图 本次构建的lvs-nat模型的示意图如下,其中所有的服务器和测试客户端均使用VMware虚拟机模拟,所使用的CentOS 7 VS内核都支持ipv ...

  8. HDU 1707 简单模拟 Spring-outing Decision

    Spring-outing Decision Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  9. Linux LVS Nginx HAProxy 优缺点

    说明:以下内容参考了抚琴煮酒的<构建高可用Linux服务器>第六章内容. 搭建负载均衡高可用环境相对简单,主要是要理解其中原理.此文描述了三种负载均衡器的优缺点,以便在实际的生产应用中,按 ...

  10. 基本二叉搜索树的第K小元素

    #include<stdio.h> #include<stdlib.h> typedef struct node *btlink; struct node { int data ...