首页 > 代码库 > POJ - 2926 Requirements
POJ - 2926 Requirements
题意:多维的曼哈顿最远距离
思路:做了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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。