1 条题解

  • 0
    @ 2025-10-8 16:50:29
    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1010;
    struct Point {
        double x, y;
        Point() {}
        Point(double a, double b) { x = a; y = b; }
        void input() { scanf("%lf%lf", &x, &y); }
        friend Point operator+(const Point &a, const Point &b) { return {a.x + b.x, a.y + b.y}; }
        friend Point operator-(const Point &a, const Point &b) { return {a.x - b.x, a.y - b.y}; }
        friend Point rotate(const Point &a, const Point &b) { // 逆转角
            return {a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x};
        }
    } P[N];
    unordered_map<double, bool> v;
    int main() {
        int n; scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
            P[i].input();
            v[P[i].x * 1e10 + P[i].y] = 1;
        }
        int ans = 0;
        for (int i = 1; i < n; i++)
            for (int j = i + 1; j <= n; j++) {
                Point p1 = P[i], p2 = P[j], p3, p4;
                p3 = p2 + rotate(p2 - p1, Point{0, 1});
                p4 = p1 + rotate(p2 - p1, Point{0, 1});
                if (v[p3.x * 1e10 + p3.y] && v[p4.x * 1e10 + p4.y]) ans++;
                
                p3 = p2 + rotate(p2 - p1, Point{0, -1});
                p4 = p1 + rotate(p2 - p1, Point{0, -1});
                if (v[p3.x * 1e10 + p3.y] && v[p4.x * 1e10 + p4.y]) ans++;
            }
        printf("%d\n", ans / 4);
        return 0;
    }
    
    • 1

    *【计算几何:转角】正方形计数(计算正方形对角坐标)

    信息

    ID
    433
    时间
    1000ms
    内存
    128MiB
    难度
    4
    标签
    递交数
    53
    已通过
    25
    上传者