Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
959 B
3
Indexable
Never
#include <stdio.h>

int main() {
    int n, xa, xb, i, j, k, count;
    int x[100], y[100];

    scanf("%d %d %d", &n, &xa, &xb);

    for (i = 0; i < n; i++) {
        scanf("%d %d", &x[i], &y[i]);
    }

    count = 0;

    for (i = 0; i < n; i++) {
        for (j = i + 1; j < n; j++) {
            if ((x[i] < xa && x[j] < xa) || (x[i] > xb && x[j] > xb)) {
                continue;
            }
            double a1 = (double)(y[i]) / (x[i] - xa);
            double a2 = (double)(y[j]) / (x[j] - xa);
            double b1 = y[i] - a1 * x[i];
            double b2 = y[j] - a2 * x[j];
            if (a1 == a2 && b1 == b2) {
                continue;
            }
            if ((x[i] < xa && x[j] >= xa) || (x[j] < xa && x[i] >= xa) ||
                (x[i] > xb && x[j] <= xb) || (x[j] > xb && x[i] <= xb)) {
                count++;
            }
        }
    }

    printf("%d\n", count);

    return 0;
}