不用说,完全的模板题,就是G++WA
http://poj.org/problem?id=2926
const int MAXN = 100010;
typedef double _int;
struct Node
{
_int a[6], b[35];
} s[MAXN];
///结构体保存每个点的维数坐标(a),处理出来的状态(b)
struct Manhattan
{
int k;
_int Min[35], Max[35];
void init()
{
REP(i, 1 << k)
{
Min[i] = 1e20, Max[i] = -1e20;
}
}
///work每次处理处所有的状态,add为增加一个点,del为删除一个点
void work(int id)
{
REP(i, 1 << k)
{
_int sum = 0;
REP(j, k)
{
if(i & (1 << j))
sum += s[id].a[j];
else
sum -= s[id].a[j];
}
s[id].b[i] = sum;
}
}
void add(int id)
{
work(id);
REP(i, 1 << k)
{
if (Min[i] > s[id].b[i]) Min[i] = s[id].b[i];
if (Max[i] < s[id].b[i]) Max[i] = s[id].b[i];
}
}
_int get()
{
_int ret = -INF;
REP(i, 1 << k)
{
_int t = Max[i] - Min[i];
if(t > ret) ret = t;
}
return ret;
}
} mandis;
int main()
{
int n;
mandis.k = 5;
RI(n);
mandis.init();
FE(kase, 1, n)
{
REP(i, mandis.k)
cin >> s[kase].a[i];
mandis.add(kase);
}
printf("%.2lf\n", mandis.get());
return 0;
}