輸入輸出皆為double
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
//int trees[6000][3]; //6000 trees, 3-dimensional
int x[6000],y[6000],z[6000];
int hist[10];
int main(){
freopen("input.txt", "r", stdin);
memset(hist,0,sizeof(hist));
double input_x, input_y, input_z;
int t=0;
while(scanf("%d %d %d", &x[t], &y[t], &z[t])!=EOF){
if(x[t]==0 && y[t]==0 && z[t]==0)break;
t++; // next tree
}
for(int i=0;i<t;i++){
double min_d=10000;
for(int j=0;j<t;j++){
if(i==j)continue;
double d=sqrt(pow(x[i]-x[j],2.0)+pow(y[i]-y[j],2.0)+pow(z[i]-z[j],2.0));
//sqrt(dx^2+dy^2+dz^2)
//printf("%.2f\n",d);
if(d<=min_d){
min_d = d;
}
}
if(min_d==10000)break;
//printf("%.2f\n",min_d);
if(min_d<1 && min_d>=0)hist[0]++;
else if(min_d>=1 && min_d<2)hist[1]++;
else if(min_d>=2 && min_d<3)hist[2]++;
else if(min_d>=3 && min_d<4)hist[3]++;
else if(min_d>=4 && min_d<5)hist[4]++;
else if(min_d>=5 && min_d<6)hist[5]++;
else if(min_d>=6 && min_d<7)hist[6]++;
else if(min_d>=7 && min_d<8)hist[7]++;
else if(min_d>=8 && min_d<9)hist[8]++;
else if(min_d>=9 && min_d<10)hist[9]++;
else;
}
for(int i=0;i<10;i++) printf("%4d",hist[i]);
printf("\n");
return 0;
}
沒有留言:
發佈留言