uva-152
来源:互联网 发布:模架编程流程 编辑:程序博客网 时间:2024/04/28 19:24
蛮水的题目,开始觉得好像直接比较大小不能过一样,结果证明是我想多了。
题意:将空间中的点按照到邻近点的最小距离分区间[0,1)~[9,10)
代码:
//#define LOCAL#include <stdio.h>#include <string.h>#include <math.h>#define MAXN 5000 + 10 // 最大树的数目 int calcDistance(int i, int j);// 参考了别人的想法,将计算的结果直接强转成int struct TreePoint // 保存每个点的位置 {int x;int y;int z;}trees[MAXN]; int result[11]; // 保存最后的结果 int main(){#ifdef LOCALfreopen("input.txt", "r", stdin);//freopen("output.txt", "w", stdout);#endifint a, b, c;int count, i, j;// 标记变量 // 数据初始化memset(trees, 0, sizeof(trees));memset(result, 0, sizeof(result));// 算法输入 count = 0;while(scanf("%d%d%d", &a, &b, &c) == 3 && a + b + c != 0){trees[count].x = a; trees[count].y = b; trees[count].z = c; count++; } for(i = count - 1; i >= 0; i--) {int mindistance = 500;for(j = count - 1; j >= 0; j--) {if(i != j){ int distance = calcDistance(i, j);// printf("distance=%d\n", distance);if(distance < mindistance){mindistance = distance;}} } //printf("mindistance=%d\n", mindistance);if(mindistance < 10)result[mindistance]++;}for(i = 0; i < 10; i++){printf("%4d", result[i]);}printf("\n");return 0;}int calcDistance(int i, int j)// 参考了别人的想法,将计算的结果直接强转成int {int x, y, z;x = trees[i].x - trees[j].x;// printf("x=%d\n", x);y = trees[i].y - trees[j].y;// printf("y=%d\n", y);z = trees[i].z - trees[j].z;// printf("z=%d\n", z);return floor(sqrt((x * x + y * y + z * z)));}
- uva-152
- uva 152
- uva 152
- uva 152
- uva-152
- UVa-152
- uva 152
- UVA 152
- UVA 152 一堆树
- UVA 152 (13.07.30)
- UVa OJ 152 排序?
- UVa 152 一堆树
- UVa 152 一堆树
- uva 152(排序,检索)
- UVA 152 解题报告
- uva
- UVA
- UVA
- asp.net 中使用Cookie 及 js 中使用Cookie
- 第十四章 信号量共享内存消息队列
- 写入cookie 的过期时间时在GMT或UTC时间格式上的兼容问题
- 第十五章 套接字连接
- 【精心整理】【实用】visual C++中最常用的类与API函数
- uva-152
- linux资源网站和ftp站点!(linux软件下载及学习)
- android_ITelephony_endCall_挂断电话
- HTML5 Canvas和EaselJS入门(译)
- vc6.0配置头文件和库文件的方法
- 云端 loadrunner 9.5 安装简单 占空间小 .net 3.5 以上 必需IE6 否则event 始终是0
- make Makefile总结
- 有关“ &”由后台输出到前端的问题
- 祝你顺利跳槽