UVA Tree's a Crowd(三维空间的点求最短距离)
2014-12-05 01:41
351 查看
Tree's a CrowdTime Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluSubmit StatusDescription
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.
Tree's a Crowd |
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
题意:输入x,y,z分别代表立体空间的坐标,然后求出这些点对于另外的其他点的最短距离,最后输出这些点的最短距离分别在0~9的个数。
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>using namespace std;struct node{ double x,y,z;}q[100100];int main(){ int k = 0; double a,b,c; while(scanf("%lf%lf%lf",&a,&b,&c)!=EOF) { if(a == 0 && b == 0 && c == 0) { break; } else { q[k].x = a; q[k].y = b; q[k].z = c; k++; } } int aa[10]; memset(aa,0,sizeof(aa)); for(int i=0;i<k;i++) { int min = 11,kk; for(int j=0;j<k;j++) { if(i != j) { kk = 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)); //printf("kk = %d\n",kk); if(min > kk) { min = kk; } } } if(min<10) { aa[min]++; } } for(int i=0;i<10;i++) { printf("%4d",aa[i]); } printf("\n"); return 0;}
相关文章推荐
- UVA 152-Tree's a Crowd(暴力求解三维坐标求最短距离)
- ZOJ3762:Pan's Labyrinth(点到直线最短距离)
- hdu 4741 Save Labman No.004 空间两直线最短距离及坐标
- 空间两条直线段的最短距离及最近点计算
- HDU 4273 Rescue(三维凸包重心到表面最短距离)
- 白话空间统计十五:多距离空间聚类分析 (Ripley's K 函数) (下)
- HDU4273(求三维凸包重心到表面的最短距离)
- 三维空间碰撞问题;空间中两直线的最短距离及最近点
- POJ 3862 Asteroids (三维凸包,求两个凸包重心到表面的最短距离)
- HDU 4741 Save Labman No.004 (2013杭州网络赛1004题,求三维空间异面直线的距离及最近点)
- poj2251 三维bfs求最短距离
- POJ 3862 Asteroids(两个三维凸包的重心到表面最短距离和)
- [ACM_几何] The Deadly Olympic Returns!!! (空间相对运动之最短距离)
- 三维空间碰撞问题;空间中两直线的最短距离及最近点
- 三维空间碰撞问题;空间中两直线的最短距离及最近点
- HDU 4741 Save Labman No.004 ( 三维计算几何 空间异面直线距离 )
- HDU 1174 爆头(三维空间中求点线距离)
- hdoj4741 求空间中不平行的两条直线的最短距离及最短线段与两直线的交点
- Trie树求多个字符串最短编辑距离的空间优化
- 三维凸包求重心到面的最短距离(HDU4273)