UVA 152-Tree's a Crowd(暴力求解三维坐标求最短距离)
2015-01-02 18:26
585 查看
Tree's a Crowd
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Submit Status
Description
![](http://uva.onlinejudge.org/components/com_onlinejudge/images/button_pdf.png)
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
![](http://uva.onlinejudge.org/external/1/152img1.gif)
is the distance
between the i'th point and its nearest neighbour(s) and
![](http://uva.onlinejudge.org/external/1/152img2.gif)
, 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.
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.
题意:给出多组树的三维坐标,让你求一棵树到其他树之间的最短距离,然后统计所有的树的最短距离在分别在0-9之间的个数
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Submit Status
Description
![](http://uva.onlinejudge.org/components/com_onlinejudge/images/button_pdf.png)
Tree's a Crowd |
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
![](http://uva.onlinejudge.org/external/1/152img1.gif)
is the distance
between the i'th point and its nearest neighbour(s) and
![](http://uva.onlinejudge.org/external/1/152img2.gif)
, 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-9之间的个数
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <algorithm> using namespace std; const int inf=0x3f3f3f; struct node { double x,y,z; }q[100010]; int main() { int i,j; int cnt=0; int minx,dis; double x,y,z; int sum[10]; while(~scanf("%lf %lf %lf",&x,&y,&z)) { if(x==0&&y==0&&z==0) break; else { q[cnt].x=x; q[cnt].y=y; q[cnt].z=z; cnt++; } } memset(sum,0,sizeof(sum)); for(i=0;i<cnt;i++) { minx=inf; for(j=0;j<cnt;j++) { if(i!=j) { dis=sqrt((q[j].x-q[i].x)*(q[j].x-q[i].x)+(q[j].y-q[i].y)*(q[j].y-q[i].y)+(q[j].z-q[i].z)*(q[j].z-q[i].z)); minx=min(minx,dis); } } if(minx<10) sum[minx]++; } for(i=0;i<10;i++) printf("%4d",sum[i]); printf("\n"); return 0; }
相关文章推荐
- 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 一堆树 检索水题+暴力
- UVA152 Tree's a Crowd
- UVA 152 Tree's a Crowd (简单计算)
- UVA 152 Tree's a Crowd
- UVA-152 Tree's a Crowd
- UVA152-Tree's a Crowd
- UVA 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