题目大意:给你一组三维空间中的点,每个点到其它点都有个距离,其中有个最小距离,如果这个最小距离小于10,就将对应的距离值的点个数加1,最后输出距离值为0,1,2,3,4,5,6,7,8,9的点的个数。
思路:两个for遍历一遍就可以了。
总结:水题,但一直没读懂题,最后题意还是百度的。。。。英语太垃圾了。
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int str[11];
double space[5010][3];
int main()
{
memset(space, 0, sizeof(space));
memset(str, 0, sizeof(str));
int num = 0;
for (int i = 0; i < 5000; i++)
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if (a == 0 && b == 0 && c == 0)
break;
space[num][0] = a;
space[num][1] = b;
space[num][2] = c;
num++;
}
for (int i = 0; i < num; i++)
{
double min = 999999999;
for (int j = 0; j < num; j++)
{
if (i != j)
{
int dis = (int)sqrt((space[i][0] - space[j][0]) * (space[i][0] - space[j][0]) + (space[i][1] - space[j][1]) * (space[i][1] - space[j][1]) + (space[i][2] - space[j][2]) * (space[i][2] - space[j][2]));
if (dis < min)
min = dis;
}
}
int s = (min + 0.5);
if (s < 10)
str[s]++;
}
for (int i = 0; i < 10; i++)
printf("%4d", str[i]);
printf("\n");
return 0;
}