POJ - 2926 Requirements
2014-04-30 22:02
246 查看
题意:多维的曼哈顿最远距离
思路:做了1,2,3维的,其实就是枚举所有绝对值的可能的表达式
思路:做了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 (空间最远曼哈顿距离)
- POJ 2926 Requirements【最远曼哈顿距离】
- Poj_2926 Requirements
- POJ 2926 Requirements(多维最远曼哈顿距离)
- POJ 2926 Requirements (多维最远曼哈顿距离)
- poj 2926 Requirements (曼哈顿距离)
- poj 2926 Requirements
- poj 2926:Requirements(最远曼哈顿距离,入门题)
- POJ 2926 Requirements
- POJ - 2926 Requirements
- poj 2926 Requirements N维最远曼哈顿距离
- 最远曼哈顿距离小结 poj 2926 Requirements&hdu 4666 Hyperspace
- [poj 2926]Requirements[最远曼哈顿距离]
- HDU 4666 Hyperspace && POJ 2926 Requirements
- poj 2926 Requirements(最大哈密顿距离,二进制)
- POJ-2926 Requirements 最远曼哈顿距离
- 【水题】 POJ 2926 Requirements
- 最远曼哈顿距离小结 poj 2926 Requirements&hdu 4666 Hyperspace
- [poj 2926]Requirements[最远曼哈顿距离]
- POJ2926-Requirements,曼哈顿距离。去掉绝对值符号暴力枚举所有情况,神薙!