QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#605189 | #8082. Minimum Euclidean Distance | Qingyyx | WA | 0ms | 4076kb | C++20 | 7.4kb | 2024-10-02 16:00:46 | 2024-10-02 16:00:47 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define enl putchar('\n')
#define all(x) (x).begin(),(x).end()
#define debug(x) printf(" "#x":%d\n",x);
using namespace std;
const int MAXN = 5000 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
typedef pair<int, int> pii;
char buf[1 << 21], * p1 = buf, * p2 = buf, obuf[1 << 21], * o = obuf, of[35];
#define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline ll qpow(ll a, ll n) { ll res = 1; while (n) { if (n & 1)res = res * a % mod; n >>= 1; a = a * a % mod; }return res; }
template <class T = int>inline T read() { T s = 0, f = 1; char c = gc(); for (; !isdigit(c); c = gc())if (c == '-')f = -1; for (; isdigit(c); c = gc())s = s * 10 + c - '0'; return s * f; }
inline void read(int* a, int n) { for (int i = 1; i <= n; ++i)a[i] = read(); }
inline int inal(char* s) { int n = 0; for (s[0] = gc(); !isalpha(s[0]); s[0] = gc()); for (; isalpha(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline void outd(auto* a, int n) { for (int i = 1; i <= n; ++i)printf("%d ", a[i]); enl; }
int n, m, q;
const double eps = 1e-9;
int sgn(double x) { return (x > eps) - (x < -eps); }
// #define sgn(x) (((x) > eps) - ((x) < -eps))
struct Point {
double x, y;
double ang;
Point(double x = 0, double y = 0) :x(x), y(y) {}
Point operator -(const Point& b)const { return Point(x - b.x, y - b.y); }
Point operator +(const Point& b)const { return Point(x + b.x, y + b.y); }
Point operator *(double k)const { return Point(x * k, y * k); }
double operator ^(const Point& b)const { return x * b.y - y * b.x; }
double operator *(const Point& b)const { return x * b.x + y * b.y; }
double operator !()const { return sqrt(*this * *this); }
bool operator <(const Point& b) const { return sgn(y - b.y) < 0 || (sgn(y - b.y) == 0 && sgn(x - b.x) < 0); }
bool operator ==(const Point& b)const { return !(*this < b) && !(b < *this); }
bool operator >(const Point& b)const { return b < *this; }
bool operator <=(const Point& b)const { return !(*this > b); }
bool operator >=(const Point& b)const { return !(*this < b); }
bool operator !=(const Point& b)const { return !(*this == b); }
Point operator /(double k)const { return Point(x / k, y / k); }
double operator ~()const { return atan2(y, x); }
Point operator -()const { return Point(-x, -y); }
double len2()const { return x * x + y * y; }
double len()const { return !*this; }
double dis(const Point& b)const { return (*this - b).len(); }
double dis2(const Point& b)const { return (*this - b).len2(); }
Point rotate(double a)const { return Point(x * cos(a) - y * sin(a), x * sin(a) + y * cos(a)); }
Point rotate(double a, const Point& o)const { return Point(x * cos(a) - y * sin(a) + o.x, x * sin(a) + y * cos(a) + o.y); }
Point unit()const { return *this / len(); }
double sqr(const Point& b, const Point& c) {
return (b - *this) ^ (c - *this);
}
double proj(const Point& b, const Point& c) {
return (b - *this) * (c - *this);
}
};
struct Line {
Point s, e;
double ang;
Line(Point s = Point(0, 0), Point e = Point(0, 0)) :s(s), e(e) {}
Line(double x1, double y1, double x2, double y2) :s(x1, y1), e(x2, y2) {}
bool pojInLine(const Point& p)const {
return sgn((p - s) * (e - s)) >= 0 && sgn((p - e) * (s - e)) >= 0;
}
bool inLine(const Point& p)const {
return sgn((p - s) ^ (e - s)) == 0 && pojInLine(p);
}
bool isparallel(const Line& b)const {
return sgn((e - s) ^ (b.e - b.s)) == 0;
}
bool isperpendicular(const Line& b)const {
return sgn((e - s) * (b.e - b.s)) == 0;
}
static Point intersection(const Line& a, const Line& b) { // 判交点 要判平行
return a.s + (a.e - a.s) * ((a.s - b.s) ^ (b.e - b.s)) / ((b.e - b.s) ^ (a.e - a.s));
}
// bool isinter(const Line& b)const {
// if (isparallel(b)) return b.inLine(s) || b.inLine(e) || inLine(b.s) || inLine(b.e);
// Point p = intersection(*this, b);
// return b.inLine(p) && (*this).inLine(p);
// }
double angle() {
return atan2(e.y - s.y, e.x - s.x);
}
bool isright(const Point& p)const {
return sgn((p - s) ^ (e - s)) > 0;
}
bool isleft(const Point& p)const {
return sgn((p - s) ^ (e - s)) < 0;
}
bool isinter(const Line& b)const {
if (b.inLine(s) || b.inLine(e) || (*this).inLine(b.s) || (*this).inLine(b.e))return true;
return (b.isright(s) ^ b.isright(e)) && ((*this).isright(b.s) ^ (*this).isright(b.e));
}
double dis(Point p) {
if (!sgn(s.dis2(e)))return s.dis(p);
if (sgn(s.proj(p, e)) < 0)return p.dis(s);
if (sgn(e.proj(p, s)) < 0)return p.dis(e);
return fabs(e.sqr(p, s)) / s.dis(e);
}
double dis(Line l) {
return min({l.dis(s), l.dis(e), (*this).dis(l.s), (*this).dis(l.e)});
}
};
struct polygon {
int n;
vector<Point>pt;
vector<Line>le;
bool inploygon(Point p) {
if ((p ^ pt[1]) > 0 || (pt.back() ^ p) > 0) return 0;
int ps = lower_bound(pt.begin() + 1, pt.end(), p, [&](const Point& a, const Point& b) {return sgn(a ^ b) > 0 || sgn(a ^ b) == 0 && a.dis2(p) < b.dis2(p); }) - pt.begin() - 1;
if (Line(pt[ps], pt[(ps + 1) % n]).inLine(p))return 1;
return sgn((p - pt[ps]) ^ (pt[(ps + 1) % n] - pt[ps])) < 0;
}
// double dis(Point p) {
// if (inploygon(p))return 0;
// double res = 2e18;
// for (int i = 0; i < n; ++i)
// res = min(res, le[i].dis(p));
// return res;
// }
double dis(Point p) {
if ((p ^ pt[1]) > 0 || (pt.back() ^ p) > 0) return le.back().dis(p);
int ps = lower_bound(pt.begin() + 1, pt.end(), p, [&](const Point& a, const Point& b) {return sgn(a ^ b) > 0 || sgn(a ^ b) == 0 && a.dis2(p) < b.dis2(p); }) - pt.begin() - 1;
if (Line(pt[ps], pt[(ps + 1) % n]).inLine(p))return 0;
if (sgn((p - pt[ps]) ^ (pt[(ps + 1) % n] - pt[ps])) < 0)return 0;
else return le[ps].dis(p);
// return sgn((p - pt[ps]) ^ (pt[(ps + 1) % n] - pt[ps])) < 0;
}
}A;
void solve() {
cin >> n >> q;
A.pt.resize(n);
A.le.resize(n);
A.n = n;
int p = 0;
for (int i = 0; i < n; ++i) {
cin >> A.pt[i].x >> A.pt[i].y;
if (A.pt[p] < A.pt[i])p = i;
}
rotate(A.pt.begin(), A.pt.begin() + p, A.pt.end());
Point bs = A.pt[0];
for (int i = 0; i < n; ++i)
A.pt[i] = A.pt[i] - bs;
for (int i = 0; i < n; ++i)
A.le[i] = Line(A.pt[i], A.pt[(i + 1) % n]);
for (int i = 1; i <= q; ++i) {
Point S, T;
cin >> S.x >> S.y >> T.x >> T.y;
S = S - bs; T = T - bs;
Point cent = (S + T) / 2;
double AC = A.dis(cent);
printf("%.12lf\n", 0.5 * cent.dis2(S) + AC * AC);
}
}
signed main(signed argc, char const* argv[]) {
clock_t c1 = clock();
#ifdef LOCAL
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
//=============================================================
ios::sync_with_stdio(false); cin.tie(nullptr);
int TxT = 1;
while (TxT--)
solve();
//=============================================================
#ifdef LOCAL
end :
cerr << "Time Used:" << clock() - c1 << "ms" << endl;
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3952kb
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.250000000000 0.750000000000 1.875000000000
result:
ok Your answer is acceptable!^ ^
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 4076kb
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:
608.500000000000 63.000000000000 1051.250000000000 66.625000000000 678.375000000000 1573.875000000000 289.875000000000 403.875000000000 689.625000000000 436.250000000000
result:
wrong answer Except 589.500000000000, but found 608.500000000000!QAQ