题意:给定n个点,然后求这n个点的两两间最大曼哈顿距离。
思路:暴力枚举。直接枚举肯定不行,d=|x1-x2|+|y1-y2|+|z1-z2|,我们只要把绝对值拆开,变成d=(x1,y1,z1)+(x2,y2,z2)逗号表示+-号,然后八种情况中找出前面最大和后面最小的即可。
code:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int INF=0x3fffffff;
const int inf=-INF;
const int N=100005;
const int M=2005;
const int mod=1000000007;
const double pi=acos(-1.0);
#define cls(x,c) memset(x,c,sizeof(x))
#define cpy(x,a) memcpy(x,a,sizeof(a))
#define ft(i,s,n) for (int i=s;i<=n;i++)
#define frt(i,s,n) for (int i=s;i>=n;i--)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lrt rt<<1
#define rrt rt<<1|1
#define middle int m=(r+l)>>1
#define lowbit(x) (x&-x)
#define pii pair<int,int>
#define mk make_pair
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);
struct node
{
int v[3];
}g[N];
int main()
{
int T,n;
scanf("%d",&T);
ft(ca,1,T){
scanf("%d",&n);
ft(i,0,n-1) ft(j,0,2)
scanf("%d",&g[i].v[j]);
//puts("buf");
int ans=inf,ml,mr,s;
ft(i,0,7)
{
ml=INF,mr=inf;
ft(j,0,n-1)
{
s=0;
ft(k,0,2)
if ((1<<k)&i) s+=g[j].v[k];
else s-=g[j].v[k];
ml=min(ml,s),mr=max(mr,s);
}
ans=max(ans,mr-ml);
}
printf("Case #%d: %d\n",ca,ans);
}
}