#54132: em3


st2037454@gmail.com (章雋輝)


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {
    int N;

    // 1. Read N
    if (scanf("%d", &N) != 1) return 0;

    // Allocate memory for coordinates
    // Using malloc is safer for larger arrays, though N<=400 fits on stack too
    double *X = (double*)malloc(N * sizeof(double));
    double *Y = (double*)malloc(N * sizeof(double));

    // 2. Read all X coordinates
    for (int i = 0; i < N; i++) {
        scanf("%lf", &X[i]);
    }

    // 3. Read all Y coordinates
    for (int i = 0; i < N; i++) {
        scanf("%lf", &Y[i]);
    }

    // Array to store all pairwise distances
    int num_dists = N * (N - 1) / 2;
    double *dists = (double*)malloc(num_dists * sizeof(double));
    int k = 0;

    // Initialize min and max trackers
    double min_d = 1e18; // Start with a very large number
    double max_d = -1.0; // Start with a very small number

    // 4. Compute all pairwise distances
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            double dx = X[i] - X[j];
            double dy = Y[i] - Y[j];
            double d = sqrt(dx*dx + dy*dy);
            
            dists[k++] = d;
            
            if (d < min_d) min_d = d;
            if (d > max_d) max_d = d;
        }
    }

    // 5. Determine histogram bounds
    int m = (int)floor(min_d);
    int M = (int)ceil(max_d);
    
    // Calculate bin width
    // If all points are identical (distance 0), avoid division by zero
    double step;
    if (M == m) {
        step = 1.0; 
    } else {
        step = (double)(M - m) / 20.0;
    }

    // 6. Fill the bins
    int bins[20] = {0}; // Initialize count to 0

    for (int i = 0; i < num_dists; i++) {
        double d = dists[i];
        
        // Calculate index
        int idx = (int)((d - m) / step);
        
        // Handle edge cases
        if (idx < 0) idx = 0;         // Should technically not happen
        if (idx >= 20) idx = 19;      // Handles d == M case or tiny float errors
        
        bins[idx]++;
    }

    // 7. Output the result
    for (int i = 0; i < 20; i++) {
        printf("%d", bins[i]);
        // Add a space after every number except the last one
        if (i < 19) printf(" ");
    }
    printf("\n");

    // Clean up memory
    free(X);
    free(Y);
    free(dists);

    return 0;
}