UVA - 152 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.
William Larch博士是著名的植物心理学家,也是“Think like a tree — Think Fi”这一短语的发明者,他发明了一种新的树木分类系统。这是一个复杂的系统,涉及一系列测量,然后组合起来为任何给定的树产生三个数字(在[0,255]范围内)。因此,每棵树可以被认为占据了三维空间中的一个点。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.
由于该过程的性质,大量树木样本的测量可能在整个可用空间中相当均匀地分布。然而Larch博士确信在这个空间的近邻之间可以找到关系。为了验证这个假设,他需要一个具有最近邻居的树木数量的直方图,这些树木位于特定的距离范围内。
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 if di is the distance between the i’th point and its nearest neighbour(s) and j ≤ di < k, 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.
编写一个程序,读取最多5000棵树的参数,并确定其中有多少具有距离小于1个单位,有多少距离大于等于1但小于2个单位,等等,最近邻居9个或以上但不到10个单位的。 因此,如果di是第i个点与其最近的邻居之间的距离j≤di<k,j和k整数且k = j + 1,则该点(树)将对直方图中的第j个bin贡献1(从零开始计数)。 例如,如果只有两个点相距1.414个单位,那么直方图将是0,2,0,0,0,0,0,0,0,0。

【输入】
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.
输入将由一系列行组成,每行由3个数字组成,范围为[0,255]。 该文件将由一个由三个零组成的行终止。

【输出】
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.
输出将包含一行,其中包含表示所需计数的10个数字,每个数字在宽度为4的字段中右对齐。

【样例输入】
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

【样例输出】
2 1 1 1 1 1 1 1 1 1

题目链接:https://cn.vjudge.net/problem/UVA-152

基础计算几何水题,关于点的操作

代码如下:

#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
static const int MAXN=5000;
struct Point{
    int x,y,z;
    Point(int _x=0,int _y=0,int _z=0){}
}point[MAXN+10];
int dis2(Point a,Point b) {
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);
}
int t[12];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0),cout.tie(0);
    int cnt=1;
    while(cin>>point[cnt].x>>point[cnt].y>>point[cnt].z && !(point[cnt].x==0 && point[cnt].y==0 && point[cnt].z==0))
        cnt++;
    for(int i=1;i<cnt;i++)
    {
        int mindis=0x3f3f3f3f;
        for(int j=1;j<cnt;j++)
        {
            if(i==j)
                continue;
            mindis=min(mindis,dis2(point[i],point[j]));
        }
        for(int i=1;i<=10;i++)
            if(mindis<i*i)
            {
                t[i]++;
                break;
            }
    }
    for(int i=1;i<=10;i++)
        cout<<setw(4)<<t[i];
    cout<<endl;
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值