首页 > 其他 > 详细

POJ - 2926 Requirements

时间:2014-05-01 17:30:37      阅读:525      评论:0      收藏:0      [点我收藏+]

题意:多维的曼哈顿最远距离

思路:做了1,2,3维的,其实就是枚举所有绝对值的可能的表达式

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 100005;
const int M = 5;
const double inf = 1e200;

struct node{
	double x[M];
}p[MAXN];
int n;
double minx[1<<M],maxx[1<<M];

double solve(){
	int i,j,k,t;
	int tmp = 1<<M;
	double s,ans = -inf;
	for (i = 0; i < tmp; i++){
		minx[i] = inf;
		maxx[i] = -inf;
	}
	for (i = 0; i < n; i++)
		for (j = 0; j < tmp; j++){
			t = j,s = 0;
			for (k = 0; k < M; k++){
				if (t & 1)
					s += p[i].x[k];
				else s -= p[i].x[k];
				t >>= 1;
			}
			if (maxx[j] < s)
				maxx[j] = s;
			if (minx[j] > s)
				minx[j] = s;
		}
	for (i = 0; i < tmp; i++)
		if (maxx[i]-minx[i] > ans)
			ans = maxx[i] - minx[i];
	return ans;
}

int main(){
	while (scanf("%d", &n) != EOF){
		for (int i = 0; i < n; i++)
			for (int j = 0; j < M; j++)
				scanf("%lf", &p[i].x[j]);
		printf("%.2f\n",solve());
	}
	return 0;
}



POJ - 2926 Requirements,布布扣,bubuko.com

POJ - 2926 Requirements

原文:http://blog.csdn.net/u011345136/article/details/24814959

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!