UVA - 152 - Tree's a Crowd

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef struct tree{
    int x,y,z;
};   
double dis(tree a,tree b)
{
   double i,j,k,sum;
   i=a.x-b.x;
   j=a.y-b.y;
   k=a.z-b.z;
   sum=i*i+j*j+k*k;
   return sqrt(sum);   
}    
int Statistic(tree a[],int b[],int n)
{
    int i,tag=0,j;
    double count;
    for(j=0;j<n;j++)
    {
        count=100000;
        for(i=0;i<n;i++)
        {
            if(i!=j)
            {
               if(dis(a[j],a[i])<count)count=dis(a[j],a[i]);
           }    
        }
        if(count<1)b[0]++;
        else if(count<2)b[1]++;
        else if(count<3)b[2]++;
        else if(count<4)b[3]++;
        else if(count<5)b[4]++;
        else if(count<6)b[5]++;
        else if(count<7)b[6]++;
        else if(count<8)b[7]++;
        else if(count<9)b[8]++;
        else if(count<10)b[9]++;
    }    
    return 0;
}            
    
int main()
{
    freopen("152in.txt","r",stdin);
    freopen("152out.txt","w",stdout);
    tree area[5500];
    int histogram[10],tag=0,i;
    for(i=0;i<10;i++)histogram[i]=0;
    while(scanf("%d%d%d",&area[tag].x,&area[tag].y,&area[tag].z))
    {
        tag++;
        if((area[tag-1].x+area[tag-1].y+area[tag-1].z)==0)break;
    }    
    tag--;
    Statistic(area,histogram,tag);
    for(i=0;i<10;i++)printf("%4d",histogram[i]);
    printf("\n");
    return 0;
}    


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值