码迷,mamicode.com
首页 > 其他好文 > 详细

POJ - 2926 Requirements

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

标签:style   blog   class   code   int   string   2014   404   name   for   amp   

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

思路:做了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

标签:style   blog   class   code   int   string   2014   404   name   for   amp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!