QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#576986 | #8082. Minimum Euclidean Distance | xinhuo2005 | WA | 0ms | 3780kb | C++20 | 2.5kb | 2024-09-19 23:47:21 | 2024-09-19 23:47:21 |
Judging History
answer
#include<bits/stdc++.h>
using ll = long long;
const int mod = 998244353;
#define pdd std::pair<double, double>
#define x first
#define y second
const double PI = acos(-1);
std::pair<double, double> operator- (const std::pair<double, double> a, const std::pair<double, double> b) {
return {a.first - b.first, a.second - b.second};
}
void solve() {
int n, q;
std::cin >> n >> q;
std::vector<std::pair<double, double>> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i].first >> a[i].second;
}
auto dis = [&](pdd a) {
return sqrt(a.x * a.x + a.y * a.y);
};
auto Dot = [&](pdd a, pdd b) {
return (a.x * b.x + a.y * b.y) / (dis(a) * dis(b));
};
auto Cro = [&](pdd a, pdd b) {
return a.x * b.y - a.y * b.x;
};
auto cmp = [&](double x) {
if (abs(x - 1e-8) <= 0) return 0.0;
return x;
};
auto isInS = [&](pdd a, pdd b, pdd x) {
};
auto isCon = [&](double xl, double yl, double xr, double yr) {
double x = (xl + xr) / 2, y = (yl + yr) / 2;
pdd o = {x, y};
std::vector<bool> ok(n);
for (int i = 0; i < n; i++) {
double x = Cro(a[i] - a[(i + 1) % n], o - a[(i + 1) % n]);
if (cmp(x) == 0.0) return true;
if (cmp(x) < 0) ok[i] = 0;
else ok[i] = 1;
}
if (*std::max_element(ok.begin(), ok.end()) == *std::min_element(ok.begin(), ok.end())) return true;
return false;
};
auto dis_ps = [&](pdd a, pdd b, pdd p) {
if ((cmp(Dot(p - a, a - b)) >= 0) ^ (cmp(Dot(p - b, a - b)) >= 0)) {
return abs(Cro(a - p, b - p)) / dis(a - b);
}
else {
return std::min(dis(p - a), dis(p - b));
}
};
while (q--) {
double xl, yl, xr, yr;
std::cin >> xl >> yl >> xr >> yr;
double ans = dis({xl - xr, yl - yr}) / 2;
ans = ans * ans / 2.0;
pdd o = {(xl + xr) / 2, (yl + yr) / 2};
if (!isCon(xl, yl, xr, yr)) {
double mn = 1e9;
for (int i = 0; i < n; i++) {
mn = std::min(mn, dis_ps(a[i], a[(i + 1) % n], o));
}
ans += mn * mn;
}
std::cout << std::fixed << std::setprecision(10);
std::cout << ans << "\n";
}
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
// std::cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3780kb
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.2500000000 0.6250000000
result:
wrong answer Except 0.750000000000, but found 0.250000000000!QAQ