zoukankan      html  css  js  c++  java
  • UVA 152 Tree's a Crowd

          原本以为精度问题,原来是最后需要一个换行。直接暴力是0.216,如果加个弱弱的排序优化一下是0.120。

    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    #include <stdlib.h>
    
    #define sqr(x) ((x)*(x))
    
    typedef struct _Point {
        double x, y, z;
    }Point;
    
    int cmp(const void *_a, const void *_b) {
        Point* a = (Point *)_a;
        Point* b = (Point *)_b;
    
        return (int)(a->x - b->x);
    }
    
    int main() {
        Point p[5005];
        int n = 0, r[15];
        double x, y, z;
    
        while (scanf("%lf%lf%lf", &x, &y, &z)) {
            if (x+y+z < 1e-9)   break;
            p[n].x = x;
            p[n].y = y;
            p[n].z = z;
            n++;
        }
    
        qsort(p, n, sizeof (p[0]), cmp);
    
        memset(r, 0, sizeof (r));
    
        for (int i=0; i<n; i++) {
            int tmin = 10;
    
            for (int j=0; j<n; j++) {
                if (i == j) continue;
    
                if (p[j].x-p[i].x > 10) // 如果x上距离超过了10不再搜索
                    break;
    
                int tmp = (int)(sqrt(sqr(p[i].x-p[j].x) + sqr(p[i].y-p[j].y)
                                    + sqr(p[i].z-p[j].z)));
                tmin = tmin < tmp ? tmin : tmp;
            }
    
            r[tmin]++;
        }
    
        for (int i=0; i<10; i++)
            printf("%4d", r[i]);
        printf("\n");
        return 0;
    }
    
  • 相关阅读:
    hdu 4496 D-City 并查集
    hdu 4493 Tutor 水题
    codeforces 377A. Puzzles 水题
    hdu 1257 小希的迷宫 并查集
    图论500题
    cdoj 93 King's Sanctuary 傻逼几何题
    cdoj 题目简单分类
    cdoj 80 Cube 水题
    cdoj 71 I am Lord Voldemort 水题
    cdoj 65 CD Making 水题
  • 原文地址:https://www.cnblogs.com/zcube/p/4194556.html
Copyright © 2011-2022 走看看