152 - Tree's a Crowd

Uva

152 - Tree's a Crowd


 Tree's a Crowd 

Dr William Larch, noted plant psychologist and inventor of the phrase``Think like a tree--Think Fig'' has invented a new classificationsystem for trees. This is a complicated system involving a series ofmeasurements which are then combined to produce three numbers (in therange [0, 255]) for any given tree. Thus each tree can be thought ofas occupying a point in a 3-dimensional space. Because of the natureof the process, measurements for a large sample of trees are likely tobe spread fairly uniformly throughout the whole of the availablespace. However Dr Larch is convinced that there are relationships tobe found between close neighbours in this space. To test thishypothesis, he needs a histogram of the numbers of trees that haveclosest neighbours that lie within certain distance ranges.

Write a program that will read in the parameters of up to 5000 treesand determine how many of them have closest neighbours that are lessthan 1 unit away, how many with closest neighbours 1 or more but lessthan 2 units away, and so on up to those with closest neighbours 9 ormore but less than 10 units away. Thus if tex2html_wrap_inline26 is thedistance between the i'th point and its nearest neighbour(s) and tex2html_wrap_inline28 , with j and k integers and k = j+1, thenthis point (tree) will contribute 1 to the j'th bin in the histogram(counting from zero). For example, if there were only two points 1.414units apart, then the histogram would be 0, 2, 0, 0, 0, 0, 0, 0, 0, 0.

Input and Output

Input will consist of aseries of lines, each line consisting of 3 numbers in the range [0,255]. The file will be terminated by a line consisting of threezeroes.

Output will consist of a single line containing the 10 numbersrepresenting the desired counts, each number right justified in afield of width 4.

Sample input

10 10 0
10 10 0
10 10 1
10 10 3
10 10 6
10 10 10
10 10 15
10 10 21
10 10 28
10 10 36
10 10 45
0 0 0

Sample output

   2   1   1   1   1   1   1   1   1   1
题目大意:

给你一堆三维坐标的点,找出最近的两点之间距离满足10个范围的点,输出满足1-10范围的个数;小于等于1的在0-1范围,小于等于2的在1-2范围,以次类推。

#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
int num[10],a[5000][3];
int main()
{
//    freopen("a.txt","r",stdin);
    int n;
    memset(num,0,sizeof(num));
    for(int i=0;;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
        if(!(a[i][0]||a[i][1]||a[i][2]))//判断条件出错了,有一个0也跳出了,看了半天才看出来;
        {
            n=i;
            break;
        }
    }
    for(int i=0;i<n;i++)
    {
        int minx=0xfffffff;
        for(int j=0;j<n;j++)
            if(i!=j)
            {
                double tmp=pow((a[i][0]-a[j][0]),2)+pow((a[i][1]-a[j][1]),2)+pow((a[i][2]-a[j][2]),2);
                int m=(int)sqrt(tmp);
                minx=min(minx,m);
            }
        if(minx<10)
            num[minx]++;
    }
    for(int i=0;i<10;i++)
        printf("%4d",num[i]);//注意格式;
    cout<<'\n';
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值