UVA 152 Tree's a Crowd
来源:互联网 发布:福建广电网络人工电话 编辑:程序博客网 时间:2024/04/26 17:04
Time limit: 3.000 seconds
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 is the distance between the i'th point and its nearest neighbour(s) and , 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 010 10 010 10 110 10 310 10 610 10 1010 10 1510 10 2110 10 2810 10 3610 10 450 0 0
Sample output
2 1 1 1 1 1 1 1 1 1答案:
#include <stdio.h>#include <iostream>#include <cmath>//#include<algorithm> using namespace std;int distance(int x1, int y1, int z1, int x2, int y2, int z2){return (int)sqrt(double((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)));}int main () {int d[10], a[5010], b[5010], c[5010];int i = 0;while (scanf("%d%d%d", &a[i], &b[i], &c[i]), a[i] || b[i] || c[i]) i++;//memset(d, 0, sizeof(d));for (i = 0; i < 10; i++) {scanf("%d",&d[i]);}for (int k = 0; k < i; k++) {int m = 10;for (int j = 0; j < i; j++) {if (k != j) m = min(m,distance(a[k], b[k], c[k], a[j], b[j], c[j]));}if (m < 10)d[m]++;}for (int k = 0; k < 10; k++)printf("%4d",d[k]);printf("\n");return 0;}
- 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
- UVa 152 - Tree's a Crowd
- HDU 5366-The mook jong(组合数学)
- 如何使用qq截图
- hdu5358 First One
- Java io文件操作(按字符、字节、行、随机读取,追加,文件操作)
- centos6.5 32位搭建hadoop2.2.0 集群
- UVA 152 Tree's a Crowd
- php框架laravel学习 二 (数据库建立迁移与建模)
- java synchronized静态同步方法与非静态同步方法,同步语句块
- 通过SQLServer的数据库邮件来发送邮件
- HDU4565 So Easy!(数学+矩阵快速幂)
- Java查看List扩容后的容量
- Java回顾之I/O
- ListView上拉加载更多
- 批量清除WPS/Word文档中的回车符