题目链接:http://poj.org/problem?id=2926

  题意:求5维空间的点集中的最远曼哈顿距离。。

  降维处理,推荐2009武森《浅谈信息学竞赛中的“0”和“1”》以及《论一类平面点对曼哈顿距离问题》

 //STATUS:C++_AC_735MS_184KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
//const LL MOD=1000000007,STA=8000010;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e50;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End double x[],low[],hig[];
int n; int main(){
// freopen("in.txt","r",stdin);
int i,j,k;
double ans,sum;
while(~scanf("%d",&n))
{
for(i=;i<;i++){
low[i]=OO;
hig[i]=-OO;
}
for(i=;i<n;i++){
scanf("%lf%lf%lf%lf%lf",&x[],&x[],&x[],&x[],&x[]);
for(j=;j<;j++){
sum=;
for(k=;k<;k++){
sum+=(j&(<<k)?x[k]:-x[k]);
}
low[j]=Min(low[j],sum);
hig[j]=Max(hig[j],sum);
}
}
ans=;
for(i=;i<;i++){
ans=Max(ans,hig[i]-low[i]);
} printf("%.2lf\n",ans);
}
return ;
}
05-01 04:03