結果
| 問題 |
No.2602 Real Collider
|
| コンテスト | |
| ユーザー |
nono00
|
| 提出日時 | 2024-01-13 00:52:53 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,494 bytes |
| コンパイル時間 | 7,948 ms |
| コンパイル使用メモリ | 449,460 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-28 00:54:04 |
| 合計ジャッジ時間 | 30,809 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 65 WA * 13 |
ソースコード
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
using BigInt = boost::multiprecision::cpp_int;
using Rational = boost::rational<BigInt>;
const BigInt INF = 1LL << 62;
struct Point {
Point() {}
Point(Rational x, Rational y): x(x), y(y) {}
Rational x, y;
};
Point mid_point(Point lhs, Point rhs) {
return Point((lhs.x + rhs.x) / 2, (lhs.y + rhs.y) / 2);
}
const Rational UNDEF(INF);
struct Line {
Rational coef;
Rational constant;
Line() {}
Line(Rational coe, Rational con): coef(coe), constant(con) {}
Line(Rational coef, Point point): coef(coef), constant(point.y - point.x * coef) {}
};
Rational 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;
Rational radius;
Circle(Point p, Rational r): center(p), radius(r) {}
};
bool inside(Circle circle, Point point) {
return 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(Rational(x), Rational(y));
}
std::vector<Line> lines(2);
for (int i = 0; i < 2; i++) {
if (points[i].y == points[i + 1].y) {
Point mid = mid_point(points[i], points[i + 1]);
lines[i] = Line(UNDEF, mid.x);
} else {
Rational 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 (lines[0].coef == lines[1].coef) {
Rational min_dist = UNDEF;
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
Point mid = mid_point(points[i], points[j]);
Rational dist(0);
for (int k = 0; k < 3; k++) {
Rational d = distance(mid, points[k]);
if (dist < d) {
dist = d;
}
}
if (dist < min_dist) {
min_dist = dist;
center = mid;
}
}
}
} else {
if (lines[0].coef == UNDEF || lines[1].coef == UNDEF) {
if (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);
}
Rational d = distance(points[0], center);
for (int i = 1; i < 3; i++) {}
}
Rational radius = 0;
for (int i = 0; i < 3; i++) {
Rational r = distance(center, points[i]);
if (radius < r) {
radius = r;
}
}
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