結果

問題 No.3005 トレミーの問題
ユーザー Tatsu_mr
提出日時 2025-01-17 22:26:46
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,926 bytes
コンパイル時間 3,708 ms
コンパイル使用メモリ 279,404 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-17 22:27:26
合計ジャッジ時間 4,724 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) For(i, 0, n)
#define rFor(i, a, b) for(int i = (a); i >= (b); i--)
#define ALL(v) (v).begin(), (v).end()
#define rALL(v) (v).rbegin(), (v).rend()

using lint = long long;
using ld = long double;

int INF = 2000000000;
lint LINF = 1000000000000000000;

using Point = pair<ld, ld>;
using Line = pair<ld, ld>;

Line get_line(Point p, Point q) {
    auto [x1, y1] = p;
    auto [x2, y2] = q;
    ld A = (y1 - y2) / (x1 - x2);
    ld B = (y2 - y1) / (x1 - x2) * x1 + y1;
    return {A, B};
}

bool same_side(Point p, Point q, Line l) {
    auto [x1, y1] = p;
    auto [x2, y2] = q;
    auto [a, b] = l;
    ld Y1 = a * x1 + b;
    ld Y2 = a * x2 + b;
    if (Y1 > y1 && Y2 > y2) {
        return true;
    }
    if (Y1 < y1 && Y2 < y2) {
        return true;
    }
    return false;
}

ld get_angle(Point p, Point q, Point r) {
    auto [x1, y1] = p;
    auto [x2, y2] = q;
    auto [x3, y3] = r;
    using Vector = pair<ld, ld>;
    Vector pq = {x2 - x1, y2 - y1};
    Vector pr = {x3 - x1, y3 - y1};
    ld ip = pq.first * pr.first + pq.second * pr.second;
    ld len_pq = sqrt(pq.first * pq.first + pq.second * pq.second);
    ld len_pr = sqrt(pr.first * pr.first + pr.second * pr.second);
    ld cosine = ip / len_pq / len_pr;
    return acos(cosine);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<Point> ps(4);
    rep(i, 4) {
        cin >> ps[i].first >> ps[i].second;
    }
    vector<int> ind = {0, 1, 2, 3};
    do {
        Point p = ps[ind[0]], q = ps[ind[1]], r = ps[ind[2]], s = ps[ind[3]];
        Line l = get_line(r, s);
        if (same_side(p, q, l)) {
            if (get_angle(p, r, s) == get_angle(q, r, s)) {
                cout << "YES\n";
                return 0;
            }
        }
    } while (next_permutation(ALL(ind)));
    cout << "NO\n";
}
0