zoukankan      html  css  js  c++  java
  • uva152

     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 classification system for trees. This is a complicated system involving a series of measurements which are then combined to produce three numbers (in the range [0, 255]) for any given tree. Thus each tree can be thought of as occupying a point in a 3-dimensional space. Because of the nature of the process, measurements for a large sample of trees are likely to be spread fairly uniformly throughout the whole of the available space. However Dr Larch is convinced that there are relationships to be found between close neighbours in this space. To test this hypothesis, he needs a histogram of the numbers of trees that have closest neighbours that lie within certain distance ranges.

     

    Write a program that will read in the parameters of up to 5000 trees and determine how many of them have closest neighbours that are less than 1 unit away, how many with closest neighbours 1 or more but less than 2 units away, and so on up to those with closest neighbours 9 or more but less than 10 units away. Thus iftex2html_wrap_inline26 is the distance between the i'th point and its nearest neighbour(s) and tex2html_wrap_inline28 , with j and k integers and k = j+1, then this 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.414 units apart, then the histogram would be 0, 2, 0, 0, 0, 0, 0, 0, 0, 0.

     

    Input and Output

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

     

    Output will consist of a single line containing the 10 numbers representing the desired counts, each number right justified in a field 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


    题目大意:求出与其他点的最小距离为0~1,1~2,....,9~10的点的个数
    计算三维空间中两点间的距离:d = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1 - z2)*(z1-z2)) 

     1 #include<cstdio>
     2 #include<string.h>
     3 #include<math.h>
     4 
     5 struct s
     6 {
     7     double x;
     8     double y;
     9     double z;
    10 };
    11 
    12 int main()
    13 {
    14     struct s dot[5010];
    15     double result,min;
    16     int i=0,j,n,m;
    17     int count[11];
    18     memset(count,0,sizeof(count));
    19     while(scanf("%lf %lf %lf",&dot[i].x,&dot[i].y,&dot[i].z) != EOF)
    20     {
    21         if(dot[i].x==0&&dot[i].y==0&&dot[i].z==0)
    22             break;
    23         i++;
    24     }
    25     n=i;
    26     for(i=0;i<n;i++)
    27     {
    28         min=100000;
    29         for(j=0;j<n;j++)
    30         {
    31             if(i!=j)
    32             {
    33                 result=sqrt((dot[i].x-dot[j].x)*(dot[i].x-dot[j].x)+(dot[i].y-dot[j].y)*(dot[i].y-dot[j].y)+(dot[i].z-dot[j].z)*(dot[i].z-dot[j].z));
    34                 if(min>result)
    35                     min=result;
    36             }
    37         }
    38         m=min;
    39         count[m]++;
    40     }
    41     for(i=0;i<10;i++)
    42     {
    43         printf("%4d",count[i]);    //宽度为4
    44     }
    45     printf("
    ");
    46     return 0;
    47 }



  • 相关阅读:
    利用window.onerror收集js代码异常
    js 基础题复习
    正则12和\1的理解
    CodeReview 方法 规范
    前端的登陆 几种类型
    http协议相关知识
    javascript中apply、call和bind的区别 详细易懂
    http常见的状态码,400,401,403 前端看
    vue中使用file-saver 下载各类文件
    js下载文件到本地各种方法总结
  • 原文地址:https://www.cnblogs.com/youdiankun/p/3679197.html
Copyright © 2011-2022 走看看