UVA152 Tree's a Crowd
来源:互联网 发布:多益网络总经理徐波 编辑:程序博客网 时间:2024/06/10 19:42
就是给出n棵树,还有这些树的坐标,然后每颗树和其他所有树都有一个距离,取其中最近的。。
统计每颗数和其他树距离中最近的那个,然后输出距离为0-9的数量。。。
暴力模拟就过了。。
AC代码:
#include<stdio.h>#include<algorithm>#include<cmath>using namespace std;class tree {public :int x,y,z;int distance;int operator-(tree tr) {return (int)sqrt( (x - tr.x) * (x - tr.x) + (y - tr.y) * (y - tr.y) + (z - tr.z) * (z - tr.z) );}};int main () {tree tr[5000];int num;int result[10] = {0};for ( int i = 0 ;;i++) {scanf("%d%d%d", &tr[i].x , &tr[i].y , &tr[i].z );if ( tr[i].x == 0 && tr[i].y == 0 && tr[i].z == 0)break;num = i + 1;} int mindi = 10000000;for( int i = 0 ; i < num ; i++) {for ( int j = 0 ;j < num ; j++) {if (i != j) {if ( tr[i] - tr[j] < mindi) {mindi = tr[i] - tr[j];}}}if ( mindi < 10 ) {result[mindi]++;}mindi = 10000000;}for ( int i = 0 ;i < 10; i++)printf ("%4d",result[i]);printf("\n");return 0;}
0 0
- UVa152 Tree's a Crowd
- UVA152-Tree's a Crowd
- UVA152 Tree's a Crowd
- Tree's a Crowd
- Tree's a Crowd
- Tree's a Crowd
- 152 - Tree's a Crowd
- 152 - Tree's a Crowd
- 152-Tree's a Crowd
- 152 - Tree's a Crowd
- UVA Tree's a Crowd
- 152 - Tree's a Crowd
- UVa OJ 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 113 Power of Cryptography
- POJ 1703 Find them, Catch them 种类并查集
- 学生信息管理系统之ADODB.recordset
- 大话重构连载6:一个真实的谎言
- 常见汽车仪表指示灯图例
- UVA152 Tree's a Crowd
- 【学生管理系统】对象变量或With块变量未设置
- SYN Flood攻击及防御方法
- UIResponder详解(响应者)
- MIT6.828 Fall 2012 Lab 1: Booting a PC
- 项目经验:css控制input无边框效果
- BSTR,_bstr_t,CComBSTR,VARIANT,_variant_t,CString的转换
- 写给我们这些浮躁 不安的程序员
- tableViewCell重用问题总结