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("\n");return 0;
}

UVA152 Tree's a Crowd【暴力+最值】相关推荐

  1. Huffman Tree哈夫曼树权值路径长度WPL计算,binarytree ,Python

    Huffman Tree哈夫曼树(霍夫曼树.赫夫曼树)权值路径长度WPL计算,binarytree ,Python 计算定义:把构建成功的哈夫曼树的每一个边缘节点(叶子)值乘以该节点到根的路径长度,最 ...

  2. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  3. AOAPC I: Beginning Algorithm Contests 题解

    AOAPC I: Beginning Algorithm Contests 题解 AOAPC I: Beginning Algorithm Contests (Rujia Liu) - Virtual ...

  4. liger UI tree DATA添加值

    首先引入相应的 ligerUI 的css和js文件 1,html <ul id="tree"></ul> 2,初始化 $("#tree" ...

  5. HDU2966 In case of failure(浅谈k-d tree)

    嘟嘟嘟 题意:给定\(n\)个二维平面上的点\((x_i, y_i)\),求离每一个点最近的点得距离的平方.(\(n \leqslant 1e5\)) 这就是k-d tree入门题了. k-d tre ...

  6. 538. Convert BST to Greater Tree 把二叉搜索树转换为累加树

    给定一个二叉搜索树(Binary Search Tree),把它转换成为累加树(Greater Tree),使得每个节点的值是原来的节点值加上所有大于它的节点值之和. 例如: 输入: 原始二叉搜索树: ...

  7. [译文] 初学者应该了解的数据结构: Tree

    原文链接:Tree Data Structures for Beginners 众成翻译地址:初学者应该了解的数据结构: Tree 系列文章,建议不了解树的同学慢慢阅读一下这篇文章,希望对你有所帮助~ ...

  8. 带父节点的平衡二叉树_深入理解(二叉树、平衡二叉树、B-Tree、B+Tree )的区别

    一.背景 一般说MySQL的索引,都清楚其索引主要以B+树为主,此外还有Hash.RTree.FullText.本文简要说明一下MySQL的B+Tree索引,以及和其相关的二叉树.平衡二叉树.B-Tr ...

  9. dsu on tree(Educational Codeforces Round 2: E. Lomsat gelral)

    题意: 一棵n个节点的树,每个节点都有一种颜色,如果颜色c在以u为根的子树中出现的次数大于等于一半,那么这个颜色就是u节点的支配色, 因为是大于等于,所以一个节点的支配色可能不止一种,求出每个节点的支 ...

最新文章

  1. 解决Docker上安装RabbitMQ后Web管理页面打不开的问题
  2. 网络切片,切开5G万亿级市场“大面包”
  3. 【ArcGIS风暴】ArcGIS中等高线高程标注/注记(打断/消隐)方法案例汇总
  4. 【转】Dynamics CRM 365零基础入门学习(二)Dynamics 插件注册的基本流程
  5. keras优化算法_目标检测算法 - CenterNet - 代码分析
  6. 【Python实战】chinesecalendar模块处理中国股市交易日期
  7. javascript中的一些核心知识点以及需要注意的地方
  8. jquery 源码分析
  9. 计算机网络技术基础试卷2,《计算机网络基础考试2》试题与答案
  10. 怎么将wmv格式转换成mp4
  11. win7计算机病毒制作教程,了解病毒的秘密,为win7打造安全盔甲
  12. USACO 土地购买
  13. php模拟邮箱登录2017,php 模拟GMAIL,HOTMAIL(MSN),YAHOO,163,126邮箱登录(原创)...
  14. android换肤的实现方案,Android 换肤的思路
  15. 与电影同行的日子(同步更新)
  16. 新浪微博和腾讯微博图标
  17. SLCP验厂辅导,发布网关是SLCP系统中用于数据托管和共享的关键角色
  18. 网站url生成二维码
  19. 台湾印象: 太平洋的风
  20. linux命令之partprobe

热门文章

  1. Html状态属性,html一些对象属性的介绍
  2. Vue-cli搭建vue基础项目
  3. SpringBoot+Nacos+Seata实现Dubbo分布式事务管理
  4. 理解lua中的metatable和__index
  5. Android 中关于Cursor类的介绍
  6. 网络游戏的客户端同步问题
  7. linux 查看 pub文件夹,linux 文件/目录的属性及权限
  8. dropdownlist三级联动怎么实现_简单三步,轻松搞定一级、二级、三级下拉菜单
  9. excel文件打不开怎么办_电脑设备管理器打不开怎么办
  10. 驱动——K7-DMA-PCIe