uva - 152 - Tree's a Crowd

#define Local
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

#define MAX 10000
#define INF 2147483647
struct Tree
{
	int x;
	int y;
	int z;
};

void Input(Tree tree[MAX], int *count)
{
	int i = 0;
	int a = 0, b = 0, c = 0;
	while (true)
	{

		cin >> a >> b >> c;
		if (0 == a && 0 == b && 0 == c)
			break;
		else
		{
			(tree)[i].x = a;
			(tree)[i].y = b;
			(tree)[i].z = c;
			i++;
			(*count)++;
		}
	}
}

int Calculate_dis(Tree t1, Tree t2)
{
	return sqrt((t1.x - t2.x)*(t1.x - t2.x) + (t1.y - t2.y)*(t1.y - t2.y) + (t1.z - t2.z)*(t1.z - t2.z));
}


int main()
{
#ifdef Local
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	Tree tree[MAX] = {0, 0, 0};
	int count = 0, min = INF, COUNT[10];
	int temp = 0;
	memset(COUNT, 0, sizeof(COUNT));
	Input(tree, &count);
	for (int i = 0; i < count; i++)
	{
		min = INF;
		for (int j = 0; j < count; j++)
		{
			if (i != j)
			{
				temp = Calculate_dis(tree[i], tree[j]);
				if (temp < min)
				{
					min = temp;
				}
			}
		}
		if (min < 10)
		{
			COUNT[min]++;
		}
	}
	for (int i = 0; i < 10; i++)
		cout << setw(4) << COUNT[i];
	cout << endl;
	return 0;
}
/*
1、数组可以传值
2、WA了好几次都是换行的原因,OJ没有PE一说,
但是题里好像没有说有换行啊。。英语渣渣啊!
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值