#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
typedef struct{
int x;
int y;
int z;
}point;
point ps[5001];
void func(int len){
float res[5001] = {0};
int dis[5001] = {0};
int fin[10] = {0};
int i,j;
for(i=0; i < len; i++){
for(j=0; j <len;j++){
dis[j] = (ps[i].x - ps[j].x)*(ps[i].x - ps[j].x)+ (ps[i].y - ps[j].y)*(ps[i].y - ps[j].y)+ (ps[i].z - ps[j].z)*(ps[i].z - ps[j].z);
}
int temp = 65535;
for( j = 0; j < len; j++){
if(dis[j] < temp && j != i){
temp = dis[j];
res[i] = sqrt(dis[j]);
}
}
memset(dis, 0, sizeof dis);
}
for(j=0; j<len;j++){
fin[(int)res[j]] += 1;
}
for(i=0; i<10; i++)
printf("%4d", fin[i]);
printf("\n");
}
int main(void){
int tx, ty, tz;
int len = 0;
/* FILE* fp = fopen("data.txt", "r");*/
while(fscanf(stdin, "%d%d%d", &tx, &ty, &tz) != EOF){
if(tx == 0 && ty == 0 && tz == 0)
break;
ps[len].x = tx;
ps[len].y = ty;
ps[len].z = tz;
len += 1;
}
func(len);
/* system("pause");*/
return 0;
}
问题: 如何用排序?
UVa OJ 152 排序?
最新推荐文章于 2013-09-05 20:17:33 发布