UVA Tree's a Crowd
来源:互联网 发布:青少年禁毒网络大赛 编辑:程序博客网 时间:2024/05/16 10:32
题目如下:
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 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.
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的点的个数。刚开始我是用三重循环,现循环距离,再用双循环遍历点,结果总是超时orz,最后改用将数组的下标极为最小距离的办法,遍历点,求出每个点的最小距离,只用两重循环,成功AC。
AC的代码如下:
- UVA Tree's a Crowd
- UVa OJ 152-Tree's a Crowd
- uva 152 Tree's a Crowd
- UVA 152 - Tree's a Crowd
- UVa 152 - Tree's a Crowd
- uva 152 - Tree's a Crowd
- UVA-152- Tree's a Crowd
- UVA 152 - Tree's a Crowd
- UVa 152 - Tree's a Crowd
- uva 152 Tree's a Crowd
- UVa 152 - Tree's a Crowd
- UVA 152 Tree's a Crowd
- UVa - 152 - Tree's a Crowd
- uva 152 - Tree's a Crowd
- uva 152 Tree's a Crowd
- UVa 152 Tree's a Crowd (暴力)
- uva - 152 - Tree's a Crowd
- UVa 152 - Tree's a Crowd
- 爱情的浓度
- Enhancing the Application class 优化Application类
- LA3263 That Nice Euler Circuit 2004_Shanghai 平面上的欧拉定理
- web版电子表格二
- “微品会”是一个类似淘宝式的开店应用
- UVA Tree's a Crowd
- openGL 日地月系统 简单solarsystem 运动绘制
- 遥望埂核战入在玷奇谋
- Enhance services 优化services
- Digital Roots
- 先序和中序重建二叉树 后序输出
- Dom4j解析带有命名空间的XML文件
- 键盘中断
- 数据恢复软件介绍