UVA - 152 Tree's a Crowd
来源:互联网 发布:畅唐网络待遇 编辑:程序博客网 时间:2024/06/07 00:27
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 is the distance between the i'th point and its nearest neighbour(s) and , withj 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<string.h>#include<stdlib.h>#include<iostream>#include<math.h>using namespace std;class Tree{public :int x;int y;int z;};Tree tree[5000];int dis(Tree a,Tree b){int cx = a.x - b.x ;int cy = a.y - b.y;int cz = a.z - b.z;return (int)sqrt(cx * cx + cy * cy + cz *cz);}int main(){int m,n,v;int t =0;while(scanf("%d%d%d",&m,&n,&v) != EOF){if(m ==0 && n ==0 && v == 0)break;tree[t].x = m;tree[t].y = n;tree[t].z = v;t++;}int min ;int ten[11];int s;memset(ten , 0 ,sizeof(ten));for(int i = 0; i < t ;i ++){int min = 10000;for(int j = 0 ;j < t;j ++){if(i == j)continue;s = dis(tree[i],tree[j]);if( s < min )min = s;}if(min < 10)ten[min]++;}for(int i = 0 ;i < 10 ;i ++)printf("%4d",ten[i]);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
- UILabel自适应高度和自动换行
- MapReduce体系结构及各种算法(1)
- 算法-Java中如何把两个数组合并为一个
- C++ Constructors FAQ
- iOS平台添加Google Admob -2/2(Unity3D开发之八)
- UVA - 152 Tree's a Crowd
- 【笔试面试——24】链表04——反转链表
- IOS中Json解析的四种方法
- sql回滚语句
- 薄膜电容器的特性
- 什么是响应式Web设计?怎样进行?
- H264关键帧和丢帧策略研究
- PHP大小写:函数名和类名不区分,变量名区分
- Android Xutils 开发框架