UVa 152 Tree's a Crowd

UVa 152 Tree's a Crowd
给出若干个三维空间中点的坐标,如果某个点到其他点的欧几里德距离(向下取整)小于10,则统计这个距离。
以下是我的代码:
#include < cstdio >
#include
< cstdlib >
#include
< cmath >
using   namespace  std;
const   int  kMaxn( 5007 );
const   int  kInf( 0x7f7f7f7f );

struct  Point
{
    
int  x,y,z;
}r[kMaxn];

int  main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/

    
int  n( 0 ),x,y,z;
    
while (scanf( " %d%d%d " , & x, & y, & z) == 3   &&  (x  ||  y  ||  z))
    {
        n
++ ;
        r[n].x
= x;
        r[n].y
= y;
        r[n].z
= z;
    }

    
int  d[ 17 ] = { 0 };
    
for ( int  i = 1 ;i <= n;i ++ )
    {
        
int  distance(kInf);
        
for ( int  j = 1 ;j <= n;j ++ )
        {
            
if (i == j)  continue ;
            
int  s(( int )sqrt((r[i].x - r[j].x) * (r[i].x - r[j].x) + (r[i].y - r[j].y) * (r[i].y - r[j].y) + (r[i].z - r[j].z) * (r[i].z - r[j].z)));
            
if (distance > s)
                distance
= s;
        }
        
if (distance <= 9 )
            d[distance]
++ ;
    }

    
for ( int  i = 0 ;i <= 9 ;i ++ )
        printf(
" %4d " ,d[i]);
    printf(
" \n " );

    
return   0 ;
}

你可能感兴趣的:(UVa 152 Tree's a Crowd)