UVA152 Tree's a Crowd暴力+最值
Posted tigerisland45
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA152 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
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
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
问题链接:UVA152 Tree‘s a Crowd
问题简述:(略)
问题分析:
????有若干颗树(<=5000),计算各个数之间的最小距离,如果小于10则统计,输出统计结果。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA152 Tree's a Crowd */
#include <bits/stdc++.h>
using namespace std;
const int N = 5000;
struct Point {
double x, y, z;
} point[N];
const int M = 10;
int cnt[M];
int distance(Point& a, Point& b)
{
return (int) sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z));
}
int main()
{
int k = 0;
while(~scanf("%lf%lf%lf", &point[k].x, &point[k].y, &point[k].z)) {
if(point[k].x == 0 && point[k].y == 0 && point[k].z == 0)
break;
k++;
}
memset(cnt, 0, sizeof(cnt));
for(int i = 0; i < k; i++) {
int mind = 99;
for(int j = 0; j < k; j++) {
if(j == i) continue;
int dist = distance(point[i], point[j]);
mind = min(mind, dist);
}
if(mind < M)
cnt[mind]++;
}
for(int i = 0; i < M; i++)
printf("%4d", cnt[i]);
printf("
");
return 0;
}
以上是关于UVA152 Tree's a Crowd暴力+最值的主要内容,如果未能解决你的问题,请参考以下文章
UVa 12325 - Zombie's Treasure Chest-[分类枚举]
UVa658 It's not a Bug, it's a Feature! (最短路,隐式图搜索)
uva658 It's not a Bug, it's a Feature!