UVA 152 - Tree's a Crowd

题目大意:给你一组三维空间中的点,每个点到其它点都有个距离,其中有个最小距离,如果这个最小距离小于10,就将对应的距离值的点个数加1,最后输出距离值为0,1,2,3,4,5,6,7,8,9的点的个数。

思路:两个for遍历一遍就可以了。

总结:水题,但一直没读懂题,最后题意还是百度的。。。。英语太垃圾了。

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int str[11];
double space[5010][3];

int main()
{
    memset(space, 0, sizeof(space));
    memset(str, 0, sizeof(str));
    int num = 0;
    for (int i = 0; i < 5000; i++)
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        if (a == 0 && b == 0 && c == 0)
            break;
        space[num][0] = a;
        space[num][1] = b;
        space[num][2] = c;
        num++;
    }
    for (int i = 0; i < num; i++)
    {
        double min = 999999999;
        for (int j = 0; j < num; j++)
        {
            if (i != j)
            {
                int dis = (int)sqrt((space[i][0] - space[j][0]) * (space[i][0] - space[j][0]) + (space[i][1] - space[j][1]) * (space[i][1] - space[j][1]) + (space[i][2] - space[j][2]) * (space[i][2] - space[j][2]));
                if (dis < min)
                min = dis;
            }
        }
        int s = (min + 0.5);
        if (s < 10)
            str[s]++;
    }
    for (int i = 0; i < 10; i++)
        printf("%4d", str[i]);
    printf("\n");

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值