XDOJ1015--Requirements
来源:互联网 发布:预算计价软件 编辑:程序博客网 时间:2024/05/17 06:44
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.
2 5 6 2 1.5
1.2 3 2 5 4
7 5 3 2 5
显然|x1 − x2| + |y1 − y2|去掉绝对值后我们可以得到四种式子,x1 + y1 - x2 − y2,x1 − y1 - x2 + y2,y1 - x1 + x2 − y2,- y1 - x1 + y2 + x2,即得x1 + y1 - (x2 + y2),x1 − y1 - (x2 - y2), y1 - x1 − (y2 −x2),- y1 - x1 −(− y2 − x2)
大家很容易就能注意到,四个等式的前后半项的符号是相同的。那么我们就可以用00,01,10,11表示这四种状态,0代表加,1代表减,就可以构造一个数组,标号便可以是0,1,2,3。如果我们找到了四种式子的最大值,再取四个式子中的最大值,不就可以得到答案了。而求每种式子的最大值方法是将式子处理后的数据中的最大值-最小值。对上述题目,是5维的情况,其去掉绝对值后会得到2^5=32种式子,从00000~11111,其中0可以代表加也可以代表减。
#include <iostream>#include <iomanip>using namespace std;const int N=100000;double req[33][N];const int D = 5;const int M = 32;int main(){ int n; while(cin>>n) { double a[D]; for(int k=0;k<n;++k) { for(int i=0;i<D;++i) cin>>a[i]; for(int i=0;i<M;++i) { req[i][k] = 0; int p = i; for(int j=0;j<D;++j) { if(p&1) req[i][k] -= a[D-1-j]; else req[i][k] += a[D-1-j]; p >>= 1; } } } double maxDiff = 0.0; for(int i=0;i<M;++i) { double maxT,minT; minT = maxT = req[i][0]; for(int j=1;j<n;++j) { if(req[i][j]>maxT) maxT = req[i][j]; if(req[i][j]<minT) minT = req[i][j]; } if(maxT-minT>maxDiff) maxDiff = maxT-minT; } cout<<setiosflags(ios::fixed)<<setprecision(2)<<maxDiff<<endl; } return 0;}
- XDOJ1015--Requirements
- Emulator Requirements
- Understanding Requirements
- Software Requirements
- Requirements analysis
- System Requirements
- Job Requirements!
- Requirements specification
- Poj_2926 Requirements
- Pku2926 Requirements
- job requirements
- poj2926 Requirements
- Microsoft .Net Core Requirements
- Requirements of error handling
- Requirements Engineering Processes
- 需求管理(Requirements Management)
- The Requirements Engineering Handbook
- std::map requirements
- poj 2186(强连通分量的kosaraju算法)
- hdu 2065 红色病毒(指数型母函数)
- NOJ1114合法日期——趣题,公式,细节
- 萌萌的单调栈 : poj2796 , poj2559 ,
- Java API 读取HDFS目录下的所有文件
- XDOJ1015--Requirements
- 【ArcGis】VS2012中丢失ArcGIS模板的解决方法
- android模拟器右侧没有键盘
- 在NavigtionBar上设置 UISearchBar
- Linux 命令ls -l 已经更改权限的命令
- uva 1564 - Widget Factory(高斯消元+逆元)
- 23种设计模式(4):建造者模式
- flash memory
- hdu-3784-继续xxx定律