本文主要是介绍UVA 152 Tree's a Crowd (简单计算),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本来以为有高明的剪枝,结果……所以暴力就行
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define sqr(x) ((x)*(x))
typedef struct _Point {double x, y, z;
}Point;int cmp(const void *_a, const void *_b) {Point* a = (Point *)_a;Point* b = (Point *)_b;return (int)(a->x - b->x);
}int main() {Point p[5005];int n = 0, r[15];double x, y, z;while (scanf("%lf%lf%lf", &x, &y, &z)) {if (x+y+z < 1e-9) break;p[n].x = x;p[n].y = y;p[n].z = z;n++;}qsort(p, n, sizeof (p[0]), cmp);memset(r, 0, sizeof (r));for (int i=0; i<n; i++) {int tmin = 10;for (int j=0; j<n; j++) {if (i == j) continue;if (p[j].x-p[i].x > 10) // 如果x上距离超过了10不再搜索break;int tmp = (int)(sqrt(sqr(p[i].x-p[j].x) + sqr(p[i].y-p[j].y)+ sqr(p[i].z-p[j].z)));tmin = tmin < tmp ? tmin : tmp;}r[tmin]++;}for (int i=0; i<10; i++)printf("%4d", r[i]);printf("\n");return 0;
}
这篇关于UVA 152 Tree's a Crowd (简单计算)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!