結果

問題 No.2602 Real Collider
ユーザー nono00nono00
提出日時 2024-01-12 22:33:44
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,454 bytes
コンパイル時間 2,886 ms
コンパイル使用メモリ 250,448 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-12 22:33:54
合計ジャッジ時間 9,043 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 35 ms
6,548 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 25 ms
6,548 KB
testcase_16 AC 40 ms
6,548 KB
testcase_17 AC 45 ms
6,548 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 52 ms
6,548 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 26 ms
6,548 KB
testcase_27 WA -
testcase_28 AC 44 ms
6,548 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 41 ms
6,548 KB
testcase_32 AC 35 ms
6,548 KB
testcase_33 AC 41 ms
6,548 KB
testcase_34 AC 41 ms
6,548 KB
testcase_35 AC 26 ms
6,548 KB
testcase_36 AC 27 ms
6,548 KB
testcase_37 AC 44 ms
6,548 KB
testcase_38 AC 46 ms
6,548 KB
testcase_39 AC 45 ms
6,548 KB
testcase_40 AC 21 ms
6,548 KB
testcase_41 AC 49 ms
6,548 KB
testcase_42 AC 38 ms
6,548 KB
testcase_43 AC 40 ms
6,548 KB
testcase_44 AC 50 ms
6,548 KB
testcase_45 AC 32 ms
6,548 KB
testcase_46 AC 31 ms
6,548 KB
testcase_47 AC 45 ms
6,548 KB
testcase_48 AC 33 ms
6,548 KB
testcase_49 AC 29 ms
6,548 KB
testcase_50 AC 23 ms
6,548 KB
testcase_51 AC 24 ms
6,548 KB
testcase_52 AC 18 ms
6,548 KB
testcase_53 AC 41 ms
6,548 KB
testcase_54 AC 32 ms
6,548 KB
testcase_55 AC 36 ms
6,548 KB
testcase_56 AC 35 ms
6,548 KB
testcase_57 AC 33 ms
6,548 KB
testcase_58 AC 14 ms
6,548 KB
testcase_59 AC 40 ms
6,548 KB
testcase_60 AC 37 ms
6,548 KB
testcase_61 AC 28 ms
6,548 KB
testcase_62 AC 42 ms
6,548 KB
testcase_63 AC 47 ms
6,548 KB
testcase_64 AC 54 ms
6,548 KB
testcase_65 AC 27 ms
6,548 KB
testcase_66 AC 44 ms
6,548 KB
testcase_67 AC 21 ms
6,548 KB
testcase_68 AC 24 ms
6,548 KB
testcase_69 AC 18 ms
6,548 KB
testcase_70 AC 21 ms
6,548 KB
testcase_71 AC 27 ms
6,548 KB
testcase_72 AC 40 ms
6,548 KB
testcase_73 AC 33 ms
6,548 KB
testcase_74 AC 41 ms
6,548 KB
testcase_75 AC 44 ms
6,548 KB
testcase_76 AC 37 ms
6,548 KB
testcase_77 AC 40 ms
6,548 KB
testcase_78 AC 49 ms
6,548 KB
testcase_79 AC 42 ms
6,548 KB
testcase_80 AC 49 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

struct Point {
    Point(long double x = 0, long double y = 0): x(x), y(y) {}
    long double x, y;
};

Point mid_point(Point lhs, Point rhs) {
    return Point((lhs.x + rhs.x) / 2, (lhs.y + rhs.y) / 2);
}

constexpr long double EPS = 1e-8;
constexpr long double UNDEF = 1e60;

bool eq(long double lhs, long double rhs) {
    return std::abs(lhs - rhs) < EPS;
}

struct Line {
    long double coef;
    long double constant;
    Line() {}
    Line(long double coe, long double con): coef(coe), constant(con) {}
    Line(long double coef, Point point): coef(coef), constant(point.y - point.x * coef) {}
};

bool eq(Line lhs, Line rhs) {
    return eq(lhs.coef, rhs.coef) && eq(lhs.constant, rhs.constant);
}

bool lt(long double lhs, long double rhs) {
    return eq(lhs, rhs) || lhs + EPS < rhs;
}

long double distance(Point lhs, Point rhs) {
    return std::hypot<long double>(lhs.x - rhs.x, lhs.y - rhs.y);
}

struct Circle {
    Point center;
    long double radius;
    Circle(Point p, long double r): center(p), radius(r) {}
};

bool inside(Circle circle, Point point) {
    return lt(distance(circle.center, point), circle.radius);
}

void solve() {
    int q;
    std::cin >> q;
    std::vector<Point> points(3);
    for (int i = 0; i < 3; i++) {
        std::cin >> points[i].x >> points[i].y;
    }
    std::vector<Line> lines(2);
    for (int i = 0; i < 2; i++) {
        if (eq(points[i].y, points[i + 1].y)) {
            Point mid = mid_point(points[i], points[i + 1]);
            lines[i] = Line(UNDEF, mid.x);
        } else {
            long double coef = (points[i + 1].x - points[i].x) / (points[i].y - points[i + 1].y);
            Point mid = mid_point(points[i], points[i + 1]);
            lines[i] = Line(coef, mid);
        }
    }

    Point center;
    if (eq(lines[0].coef, lines[1].coef)) {
        long double min_dist = 1e18;
        for (int i = 0; i < 3; i++) {
            for (int j = i + 1; j < 3; j++) {
                Point mid = mid_point(points[i], points[j]);
                long double dist = 0;
                for (int k = 0; k < 3; k++) {
                    dist = std::max(dist, distance(mid, points[k]));
                }
                if (dist < min_dist) {
                    min_dist = dist;
                    center = mid;
                }
            }
        }
    } else {
        if (eq(lines[0].coef, UNDEF) || eq(lines[1].coef, UNDEF)) {
            if (eq(lines[0].coef, UNDEF)) std::swap(lines[0], lines[1]);
            center.x = lines[1].constant;
            center.y = lines[0].coef * center.x + lines[0].constant;
        } else {
            center.x = (lines[1].constant - lines[0].constant) / (lines[0].coef - lines[1].coef);
            center.y = (lines[0].coef * lines[1].constant - lines[0].constant * lines[1].coef)
                       / (lines[0].coef - lines[1].coef);
        }
        long double d = distance(points[0], center);
        for (int i = 1; i < 3; i++) {}
    }

    long double radius = 0;
    for (int i = 0; i < 3; i++) {
        radius = std::max(radius, distance(center, points[i]));
    }
    Circle circle(center, radius);
    while (q--) {
        Point p;
        std::cin >> p.x >> p.y;
        std::cout << (inside(circle, p) ? "Yes" : "No") << '\n';
    }
}

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
    std::cout << std::fixed << std::setprecision(16);
    int t = 1;

    while (t--) solve();
}
0