POJ - 2926 Requirements
来源:互联网 发布:客户数据分析的流程 编辑:程序博客网 时间:2024/06/07 05:08
题目:
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 Nlines each describe the requirements of a university. A university X is described by the five non-negative real numbers x1 x2 x3 x4x5.
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
点(x1,x2,x3,x4,x5)和(y1,y2,y3,y4,y5)的曼哈顿距离是:
a1(x1-y1)+a2(x2-y2)+a3(x3-y3)+a4(x4-y4)+a5(x5-y5),其中a取1或者-1
在这样的32个组合中,最大的就是曼哈顿距离了。
用了一点点状态压缩的技巧,用0-31表示这32个二进制5位数,然后把1,0变成1,-1
这样就取遍了32个组合。
代码:
#include<iostream>#include<limits>using namespace std;double list[32];double maxs[32];double mins[32];int main(){for (int i = 0; i < 32; i++)maxs[i] = numeric_limits<double>::max()*-1;for (int i = 0; i < 32; i++)mins[i] = numeric_limits<double>::max();int n;cin >> n;double x;while (n--){for (int i = 0; i < 32; i++)list[i] = 0;for (int k = 0; k < 5; k++){cin >> x;for (int i = 0; i < 32; i++)list[i] += x*((i >> k) % 2 * 2 - 1);}for (int i = 0; i < 32; i++)if (list[i]>maxs[i])maxs[i] = list[i];for (int i = 0; i < 32; i++)if (list[i]<mins[i])mins[i] = list[i];}double m = 0;for (int i = 0; i < 32; i++)if (maxs[i] - mins[i]>m)m = maxs[i] - mins[i];printf("%.2f\n", m);return 0;}
- poj 2926 Requirements
- POJ - 2926 Requirements
- 【水题】 POJ 2926 Requirements
- POJ - 2926 Requirements
- poj 2926 Requirements (曼哈顿距离)
- POJ 2926 Requirements【最远曼哈顿距离】
- [poj 2926]Requirements[最远曼哈顿距离]
- poj 2926 Requirements N维最远曼哈顿距离
- 最远曼哈顿距离小结 poj 2926 Requirements&hdu 4666 Hyperspace
- 最远曼哈顿距离小结 poj 2926 Requirements&hdu 4666 Hyperspace
- POJ 2926 Requirements(多维最远曼哈顿距离)
- poj 2926 Requirements(最大哈密顿距离,二进制)
- POJ 2926 Requirements (多维最远曼哈顿距离)
- poj 2926 Requirements 【5维点集最远曼哈顿距离】
- POJ 2926 Requirements (空间最远曼哈顿距离)
- Emulator Requirements
- Understanding Requirements
- Software Requirements
- Linux中设置服务自启动的三种方式
- 关于eclipse无法修改Server Locations选项
- 点击小图显示大图 Alertdialog 全屏都可以
- 利用栈实现计算器,先转换为逆波兰式之后运算
- C#创建线程传递参数
- POJ - 2926 Requirements
- 通过ipv6免流上网教程
- Session总结
- 最短路径条数问题 - 广度优先搜索
- (3)C和C++的区别!
- 基本网络概念
- spring框架AOP的理解,程序高类聚的体现
- C++中基类继承 enable_shared_from_this 之后派生类无法使用 shared_from_this() 的解决方法
- 乔布斯2005年斯坦福大学毕业典礼演讲原文 – Stay hungry, stay foolish