uva 152(排序,检索)
来源:互联网 发布:淘宝快递助手怎么授权 编辑:程序博客网 时间:2024/05/16 18:40
题目:
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 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
题解:空间直角坐标系的点,每个点和其他点的距离最短的并且强制转换小于10的让该距离的个数++,最后输出十个数字分别是最小距离是0到9的个数。。
#include <iostream>#include <cstdio>#include <cmath>using namespace std;const int INF = 0x3f3f3f3f;struct Point {int x, y, z, distance;}p[5005];int count(int i, int j) {return (int) sqrt(((p[i].x - p[j].x) * (p[i].x - p[j].x)) + ((p[i].y - p[j].y) * (p[i].y - p[j].y)) + ((p[i].z - p[j].z) * (p[i].z - p[j].z)));}int main() {int n = 0, ans[10] = {0};while (~scanf("%d%d%d", &p[n].x, &p[n].y, &p[n].z) && (p[n].x || p[n].y || p[n].z)) {p[n].distance = INF;n++;}int temp, i, j;for (i = 0; i < n; i++) {for (j = i + 1; j < n; j++) {int temp = count(i, j);if (p[i].distance > temp)p[i].distance = temp;if (p[j].distance > temp)p[j].distance = temp;}if (p[j].distance >= 0 && p[i].distance <= 9)ans[p[i].distance]++;}for (i = 0; i < 10; i++)printf("%4d", ans[i]);cout << endl;return 0;}
- uva 152(排序,检索)
- uva 10474(排序,检索)
- uva 120(排序,检索)
- uva 156(排序、检索)
- uva 123(排序、检索)
- uva 10194(排序、检索)
- uva 755(排序、检索)
- uva 10785(排序、检索)
- uva 400(排序、检索)
- uva 299(排序、检索)
- UVA 10420(排序检索)
- UVA 排序与检索1
- UVA 排序与检索2
- UVA 152 (暑假-排序、检索 -D - Tree's a Crowd)
- uva 156 Ananagrams(检索+sort排序)
- uva 755 487--3279(检索+排序)
- uva 10420 List of Conquests(检索+排序)
- UVA 10420 (暑假-排序、检索 -B - List of Conquests)
- 汇编push ds;sub ax,ax;push ax和ret的作用
- OpenCV图像的使用和操作
- Spring源码学习IOC(6):IoC容器的高级特性
- 使用Hive读取Hbase中的数据
- 有一种设计风格叫RESTful
- uva 152(排序,检索)
- java web jsp学习笔记--概述-常用语法,指令,动作元素,隐式对象,域对象
- OpenWrt netifd 生成resolv.conf.auto
- 单词接龙
- POJ 3020:Antenna Placement(无向二分图的最小路径覆盖)
- 设计模式——单例模式
- MLlib-Basics (III)
- 发动机的飞机飞机飞
- 黑马程序员---IO(输入输出)