zoukankan      html  css  js  c++  java
  • 152

    题目大意:找出三维坐标中一个点周围距离[1,2),[2,3),.....的点的个数

    学习了一下c++ 输出格式控制

    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


     1 #include <cstdio>
     2 #include <iostream>
     3 #include <cmath>
     4 #include <iomanip>
     5 using namespace std;
     6 
     7 const int maxn = 5000+10;
     8 int num[11];
     9 
    10 int X[maxn][3];
    11 int px;
    12 
    13 inline int dis(int x1,int x2,int y1,int y2,int z1,int z2){
    14     
    15     int a = (x1-x2)*(x1-x2);
    16     int b = (y1-y2)*(y1-y2);
    17     int c = (z1-z2)*(z1-z2);
    18     return sqrt(a+b+c);
    19 }
    20 int main()
    21 {
    22     int x,y,z;
    23     cin>>x>>y>>z;
    24     while(x!=0|| y!=0||z!=0)
    25     {
    26         X[px][0]=x;
    27         X[px][1]=y;
    28         X[px++][2]=z;
    29         cin>>x>>y>>z;
    30     }
    31     
    32     int a =0;
    33     int max = 10000;
    34     for(int i=0;i<px;i++)
    35     {
    36         max=10000;
    37         for(int j=0;j<px;j++)
    38         {
    39             if(i==j)continue;
    40             a = dis(X[i][0],X[j][0],X[i][1],X[j][1],X[i][2],X[j][2]);
    41             if(a<max)
    42                 max=a;
    43         }
    44         if(max>=10)continue;
    45         num[max]++;
    46     }
    47     
    48     for(int i=0;i<10;i++)
    49     {
    50         cout<<setw(4)<<num[i];
    51     }
    52     cout<<endl;
    53     
    54     return 0;
    55 }
  • 相关阅读:
    Mac 安装实用开发软件和日常软件清单
    Docker zabbix-agent 监控 docker tomcat 多实例
    zabbix 组件监控概述
    实况8操作指南
    关于哲哲跳舞这件小事儿
    左耳听风笔记摘要(11-12)程序的异常处理
    左耳听风笔记摘要(07-10)推荐书单/Go/Docker
    从零开始的vue学习笔记(一)
    简述Spark工作流程
    opengl简单入门实例
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3376125.html
Copyright © 2011-2022 走看看