uva152 Tree's a Crowd

看不懂题目意思啊还是,郁闷,做了两天。只要不题目意思了看懂了,代码没有任何难度,就是让你统计一下在所给的三维空间的树的位置中,两棵树之间距离在0--9内的情况各有多少种

View Code
 1 #include<stdio.h>
 2 #include<math.h>
 3 int main()
 4 {
 5     int i, j, min, f[11] = {0}, x[5020], y[5020], z[5020], top = 0, a, c, b, k;
 6     while(scanf("%d%d%d",&a, &b, &c) && (a || b || c))
 7     {
 8         x[top] = a;
 9         y[top] = b;
10         z[top] = c;
11         top++;
12     }
13     for(i = 0;i < top; i++)
14     {
15         k = 0;
16         min = 10000;
17         for(j = 0;j < top; j++)
18         {
19             if(i != j)
20             {
21                 a = abs(x[i]-x[j]);
22                 b = abs(y[i]-y[j]);
23                 c = abs(z[i]-z[j]);
24                 k = (int)sqrt(a*a+b*b+c*c);
25                 if(min > k)
26                 min = k;
27             }    
28         }
29         if(min < 10)
30             f[min]++;
31     }
32     for(i = 0;i < 10; i++)
33         printf("%4d",f[i]);
34     printf("\n");
35     return 0;
36 }
原文地址:https://www.cnblogs.com/SDUTYST/p/2537003.html