UVa 152 - Tree's a Crowd

来源:互联网 发布:整容软件 编辑:程序博客网 时间:2024/06/05 11:10

题目:一直三维空间中的整数坐标点,求每个点到其他点的最小距离的整数值,统计值0-9出现的次数。

分析:简单题。直接暴力求解即可。

说明:注意引用的库文件。

#include <iostream>#include <cstdlib>#include <cstdio>#include <cmath>using namespace std;typedef struct pnode{int x,y,z;}point;point P[5004];int Dist[10];double dist( point a, point b ){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z)+0.0);}int main(){int count = 0;while ( ~scanf("%d%d%d",&P[count].x,&P[count].y,&P[count].z) ) {if ( P[count].x + P[count].y + P[count].z == 0 )break;count ++;}for ( int i = 0 ; i < 10 ; ++ i )Dist[i] = 0;for ( int i = 0 ; i < count ; ++ i ) {double min = 10,temp;for ( int j = 0 ; j < count ; ++ j ) if ( i != j ) {temp = (int)dist( P[i], P[j] );if ( min > temp )min = temp;}if ( min < 10 )Dist[int(min)] ++;}for ( int i = 0 ; i < 10 ; ++ i )printf("%4d",Dist[i]);printf("\n");return 0;}

0 0
原创粉丝点击