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;}


1 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 目前公司账面亏损有人要入股怎么办 土地确权后没有土地的人怎么办 老板不发工资跑路了怎么办 别人登录了我的美团账号怎么办 月嫂家政公司快坚持不下去了怎么办 华硕飞马4a手机发热怎么办 超级必发指数手机页面没曲线怎么办 唐小僧理财暴雷了投资者该怎么办 教师资格证面试准考证号忘了怎么办 初中学校说处分不给毕业证怎么办? 自动档一键打火的车没电了怎么办 物流代收货款一直拿不到钱怎么办 丰巢快递柜收不到验证码怎么办 拼多多三级惩罚下架3天怎么办 在万达买的衣服穿一次烂了怎么办 内蒙古对于没有地的农民改怎么办 微信号码重新注册后回零钱怎么办 安卓系统文件苹果手机打不开怎么办 课题必须发表论文吗?查重怎么办 学信网学籍绑定输错5次怎么办 大学学校图书馆借的书丢了怎么办 借阅机里的图书不显示书名怎么办 苹果6s锁屏密码忘了怎么办 父亲去世后妈将父亲存款带走怎么办 狗和别的狗打架腿瘸了怎么办 神经病砍人警察不积极处理怎么办 才买了车里面的气味很大怎么办 家里装修两年了很大的木味怎么办 装修一年的房子夏天味很大怎么办 死了怕下地狱活着又受煎熬怎么办 狗狗的疫苗证丢了怎么办 剃了毛的狗不睡觉怎么办 家里的小狗送人了孩子一直哭怎么办 半个月的小狗一天没拉屎怎么办 把狗狗的毛剃了怎么办 用了维a酸乳膏过敏怎么办 药水点痣留下的红印怎么办 小孩牙齿被虫子吃了个洞怎么办 一岁宝宝贫血值是84怎么办 荒岛求生手机版被困在石室里怎么办 工伤认定期间被厂里辞退工资怎么办