QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569864 | #8082. Minimum Euclidean Distance | longyin | WA | 0ms | 3944kb | C++20 | 2.3kb | 2024-09-17 11:36:43 | 2024-09-17 11:36:43 |
Judging History
answer
#include <bits/stdc++.h>
//#define int long long
#define endl "\n"
using namespace std;
using ll = long long;
const int INF = 1e9;
const int N = 5e3 + 5;
const double eps = 1e-9;
struct Point {
double x, y;
using Vec = Point;
Point operator + (const auto& p) {
return {x + p.x, y + p.y};
}
Point operator - (const auto& p) {
return {x - p.x, y - p.y};
}
Point operator * (const double k) {
return {x * k, y * k};
}
Point operator / (const int k) {
return {x / k, y / k};
}
double dot(const auto& p) {
return x * p.x + y * p.y;
}
double cross(const Vec& p) {
return x * p.y - y * p.x;
}
double dis(const Point& p) {
return sqrt(dis2(p));
}
double dis2(const Point& p) {
return pow(x - p.x, 2) + pow(y - p.y, 2);
}
double len() {
return sqrt(len2());
}
double len2() {
return pow(x, 2) + pow(y, 2);
}
} points[N];
using Vec = Point;
double pToSegDis(Point& p, Point& a, Point& b) {
double k = -1 / ((a.y - b.y) / (a.x - b.x));
double d = abs((b - a).cross(p - a)) / a.dis(b);
double m = sqrt(1 + k * k);
double n = d / m;
Point s = {1, k};
Point h = p + s * n;
double res = (b - a).dot(h - a) / a.dis(b);
if (res <= -eps)
return p.dis2(a);
else if (res >= 1 + eps)
return p.dis2(b);
else
return p.dis2(h);
}
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> points[i].x >> points[i].y;
}
points[n + 1] = points[1];
for (int i = 1; i <= q; i++) {
Point p, q;
cin >> p.x >> p.y >> q.x >> q.y;
Point o = (p + q) / 2;
double r = p.dis(q) / 2;
double res = INF;
bool flag = false;
for (int j = 1; j <= n; j++) {
if ((points[j + 1] - points[j]).cross(o - points[j]) <= eps) {
flag = true;
}
double d = pToSegDis(o, points[j], points[j + 1]);
res = min(res, d);
}
if (!flag)
res = 0;
res += r * r / 2;
cout << fixed << setprecision(10) << res << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3928kb
input:
4 3 0 0 1 0 1 1 0 1 0 0 1 1 1 1 2 2 1 1 2 3
output:
0.2500000000 0.7500000000 1.8750000000
result:
ok Your answer is acceptable!^ ^
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3944kb
input:
48 10 -30 0 -29 -4 -28 -7 -27 -9 -25 -12 -22 -16 -21 -17 -17 -20 -14 -22 -12 -23 -9 -24 -5 -25 -4 -25 0 -24 3 -23 5 -22 8 -20 12 -17 13 -16 16 -12 18 -9 19 -7 20 -4 21 0 21 1 20 5 19 8 18 10 16 13 13 17 12 18 8 21 5 23 3 24 0 25 -4 26 -5 26 -9 25 -12 24 -14 23 -17 21 -21 18 -22 17 -25 13 -27 10 -28 ...
output:
589.5000000000 51.4705882353 1051.2500000000 66.6250000000 174.1250000000 562.6750000000 272.8750000000 287.8750000000 689.6250000000 436.2500000000
result:
wrong answer Except 272.394230769200, but found 272.875000000000!QAQ