結果
| 問題 |
No.2602 Real Collider
|
| コンテスト | |
| ユーザー |
nono00
|
| 提出日時 | 2024-01-12 23:26:15 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,669 bytes |
| コンパイル時間 | 3,322 ms |
| コンパイル使用メモリ | 265,608 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-28 00:12:49 |
| 合計ジャッジ時間 | 14,757 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 73 |
ソースコード
#include <bits/stdc++.h>
int sign(long long a) {
return a > 0 ? 1 : a < 0 ? -1 : 0;
}
const long long INF = 1e9;
struct Qu {
long long a, b;
Qu(): a(0), b(0) {}
Qu(long long a_, long long b_): a(a_), b(b_) {
if (b == 0) {
a = INF;
b = 0;
} else {
long long g = std::gcd(std::abs(a), std::abs(b));
a /= g;
b /= g;
if (sign(a) != sign(b)) {
if (b < 0) {
a = -a;
b = -b;
}
} else if (a < 0) {
a = -a;
b = -b;
}
}
}
Qu(long long v): Qu(v, 1) {}
};
std::ostream& operator<<(std::ostream& os, Qu q) {
os << q.a << '/' << q.b;
return os;
}
Qu operator+(Qu lhs, Qu rhs) {
long long b = lhs.b * rhs.b;
long long a = lhs.a * rhs.b + rhs.a * lhs.b;
return Qu(a, b);
}
Qu operator-(Qu lhs, Qu rhs) {
long long b = lhs.b * rhs.b;
long long a = lhs.a * rhs.b - rhs.a * lhs.b;
return Qu(a, b);
}
Qu operator*(Qu lhs, Qu rhs) {
return Qu(lhs.a * rhs.a, lhs.b * rhs.b);
}
Qu operator/(Qu lhs, Qu rhs) {
return Qu(lhs.a * rhs.b, lhs.b * rhs.a);
}
bool eq(Qu lhs, Qu rhs) {
return lhs.a == rhs.a && lhs.b == rhs.b;
}
bool lt(Qu lhs, Qu rhs) {
Qu l(lhs.a * rhs.b, lhs.b * rhs.b);
Qu r(rhs.a * lhs.b, rhs.b * lhs.b);
return l.a <= r.a;
}
struct Point {
Point() {}
Point(Qu x, Qu y): x(x), y(y) {}
Qu x, y;
};
Point mid_point(Point lhs, Point rhs) {
return Point((lhs.x + rhs.x) / 2, (lhs.y + rhs.y) / 2);
}
const Qu UNDEF(INF, 0);
struct Line {
Qu coef;
Qu constant;
Line() {}
Line(Qu coe, Qu con): coef(coe), constant(con) {}
Line(Qu coef, Point point): coef(coef), constant(point.y - point.x * coef) {}
};
Qu distance(Point lhs, Point rhs) {
return (lhs.x - rhs.x) * (lhs.x - rhs.x) + (lhs.y - rhs.y) * (lhs.y - rhs.y);
}
struct Circle {
Point center;
Qu radius;
Circle(Point p, Qu 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++) {
int x, y;
std::cin >> x >> y;
points[i] = Point(x, 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 {
Qu 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)) {
Qu min_dist(INF);
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
Point mid = mid_point(points[i], points[j]);
Qu dist(0);
for (int k = 0; k < 3; k++) {
Qu d = distance(mid, points[k]);
if (lt(dist, d)) {
dist = d;
}
}
if (lt(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);
}
Qu d = distance(points[0], center);
for (int i = 1; i < 3; i++) {}
}
Qu radius = 0;
for (int i = 0; i < 3; i++) {
Qu r = distance(center, points[i]);
if (lt(radius, r)) {
radius = r;
}
}
std::cerr << center.x << ' ' << center.y << ' ' << radius << std::endl;
Circle circle(center, radius);
while (q--) {
int x, y;
std::cin >> x >> y;
Point p(x, 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();
}
nono00