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 }
  • 相关阅读:
    【前端进阶】VUE高性能组件引用
    「前端进阶」高性能渲染十万条数据(虚拟列表) (自己修改版本)
    页面缓存、离线存储技术localforage(案例篇)
    页面缓存、离线存储技术localforage(介绍篇)
    websocket快速搭建(node+websocket)
    一款程序员的杀手级应用:TabNine代码补全工具
    如何把es6的代码转成es5,ECMAScript 2015+代码转换神器——Babel
    如何使用echarts画一个简单k线图
    深入浅出理解 . 深拷贝 . 浅拷贝
    JS高级一看就懂什么是原型链
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3376125.html
Copyright © 2011-2022 走看看