题目大意:给出一系列的点,求点与其他点的距离的最小值,如果最小之小于0,则记录
解题思路:用数组存放那些最小值的数量
#include<cstdio>
#include<cstring>
#include<cmath>
struct Point {
int x;
int y;
int z;
}p[10000];
int main() {
int num = 0;
int count[10];
memset(count,0,sizeof(count));
while(scanf("%d%d%d",&(p[num].x), &(p[num].y), &(p[num].z))) {
if(p[num].x == 0 && p[num].y == 0 && p[num].z == 0)
break;
num++;
}
Point number;
int temp;
for(int i = 0; i < num; i++) {
int min = -2;
for(int j = 0; j < num; j++) {
if(j != i) {
number.x = (p[i].x - p[j].x) * (p[i].x - p[j].x);
number.y = (p[i].y - p[j].y) * (p[i].y - p[j].y);
number.z = (p[i].z - p[j].z) * (p[i].z - p[j].z);
temp = (int)sqrt(number.x + number.y + number.z);
if(min < 0 || min > temp)
min = temp;
}
}
if(min < 10)
count[min]++;
}
for(int i = 0; i < 10; i++)
printf("%4d", count[i]);
printf("\n");
return 0;
}