QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#313798 | #8082. Minimum Euclidean Distance | EndPB | WA | 380ms | 7072kb | C++17 | 6.2kb | 2024-01-24 23:52:05 | 2024-01-24 23:52:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ld long double
#define Vector Point
#define S(x) (x)*(x)
#define N 100010
const int Kep = 10;
const ld eps = 1e-9, pi = acosl(-1.0), Mn = powl(10.0, -Kep);
inline int sign(ld a) { return a < -eps ? -1 : (a > eps ? 1 : 0); }
inline ld Abs(ld a) { return a * sign(a); }//取绝对值
inline void Out(long double a, int k = Kep) {
if (-Mn < a && a < Mn) a = 0;
cout << fixed << setprecision(Kep) << a;//<iomanip>
}
struct Point {
ld x, y;
Point(ld a = 0, ld b = 0) { x = a, y = b; }
inline void in() { cin >> x >> y; }
inline void out() {
Out(x);
cout << " ";
Out(y);
cout << endl;
}
};
inline ld Dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }//【点积】
inline ld Cro(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }//【叉积】
inline ld Len(Vector a) { return sqrtl(Dot(a, a)); }//【模长】
inline ld Angle(Vector a, Vector b) { return acosl(Dot(a, b) / Len(a) / Len(b)); }//【两向量夹角】
inline Vector Normal(Vector a) { return Vector(-a.y, a.x); }//【法向量】
inline Vector operator+(Vector a, Vector b) { return Vector(a.x + b.x, a.y + b.y); }
inline Vector operator-(Vector a, Vector b) { return Vector(a.x - b.x, a.y - b.y); }
inline Vector operator*(Vector a, ld b) { return Vector(a.x * b, a.y * b); }
bool operator<(const Point &a, const Point &b) { return Abs(a.x - b.x) < eps ? a.y < b.y : a.x < b.x; }
inline bool operator==(Point a, Point b) { return !sign(a.x - b.x) && !sign(a.y - b.y); }//两点坐标重合则相等
inline bool same_dir(Vector a, Vector b) { return sign(Cro(b, a)) == 0 && sign(Dot(b, a)) > 0; }//判断两向量是否同向,退化为点后会返回0
inline int pan_PS(Point p, Point a, Point b) {//【判断点P是否在线段AB上】
return !sign(Cro(p - a, b - a)) && sign(Dot(p - a, p - b)) <= 0;//做法一
// return !dcmp(Cro(p-a,b-a))&&dcmp(min(a.x,b.x)-p.x)<=0&&dcmp(p.x-max(a.x,b.x))<=0&&dcmp(min(a.y,b.y)-p.y)<=0&&dcmp(p.y-max(a.y,b.y))<=0;//做法二
//PA,AB共线且P在AB之间(其实也可以用len(p-a)+len(p-b)==len(a-b)判断,但是精度损失较大)
}
inline int pan_PL(Point p, Point a, Point b) {//【判断点P是否在直线AB上】
return !sign(Cro(p - a, b - a));//PA,AB共线
}
inline ld dis_PL(Point p, Point a, Point b) {
if (a == b)return Len(p - a);//AB重合
Vector x = p - a, y = p - b, z = b - a;
return Abs(Cro(x, z) / Len(z));//面积除以底边长
}
inline ld dis_PS(Point p, Point a, Point b) {//【点P到线段AB距离】
if (a == b)return Len(p - a);//AB重合
Vector x = p - a, y = p - b, z = b - a;
if (sign(Dot(x, z)) < 0)return Len(x);//P距离A更近
if (sign(Dot(y, z)) > 0)return Len(y);//P距离B更近
return Abs(Cro(x, z) / Len(z));//面积除以底边长
}
inline Point FootPoint(Point p, Point a, Point b) {//点P到直线AB的垂足
Vector x = p - a, y = p - b, z = b - a;
ld len1 = Dot(x, z) / Len(z), len2 = -1.0 * Dot(y, z) / Len(z);//分别计算AP,BP在AB,BA上的投影
return a + z * (len1 / (len1 + len2));//点A加上向量AF
}
inline Point poi_PS(Point p, Point a, Point b) {//【点P到线段AB的最近位置】
if (a == b)return Len(p - a);//AB重合
Vector x = p - a, y = p - b, z = b - a;
if (sign(Dot(x, z)) < 0)return a;//P距离A更近
if (sign(Dot(y, z)) > 0)return b;//P距离B更近
return FootPoint(p, a, b);//返回垂足
}
inline Point Symmetry_PL(Point p, Point a, Point b) {//【点P关于直线AB的对称点】
return p + (FootPoint(p, a, b) - p) * 2;//将PF延长一倍即可
}
inline Point cross_LL(Point a, Point b, Point c, Point d) {//【两直线AB,CD的交点】
Vector x = b - a, y = d - c, z = a - c;
return a + x * (Cro(y, z) / Cro(x, y));//点A加上向量AF
}
inline int pan_cross_LS(Point a, Point b, Point c, Point d) {//【判断直线AB与线段CD是否相交】
return pan_PL(cross_LL(a, b, c, d), c, d);//直线AB与直线CD的交点在线段CD上
}
inline int pan_cross_SS(Point a, Point b, Point c, Point d) {//【判断两线段AB,CD是否相交】
ld c1 = Cro(b - a, c - a), c2 = Cro(b - a, d - a);
ld d1 = Cro(d - c, a - c), d2 = Cro(d - c, b - c);
return sign(c1) * sign(c2) < 0 && sign(d1) * sign(d2) < 0;//分别在两侧
}
inline int PIP(Point *P, int n, Point a) {//【射线法】判断点A是否在任意多边形Poly以内 O(n)
int cnt = 0;
ld tmp;
for (int i = 1; i <= n; ++i) {
int j = i < n ? i + 1 : 1;
if (pan_PL(a, P[i], P[j]))return 2;//点在多边形上
if (a.y >= min(P[i].y, P[j].y) && a.y < max(P[i].y, P[j].y))//纵坐标在该线段两端点之间
tmp = P[i].x + (a.y - P[i].y) / (P[j].y - P[i].y) * (P[j].x - P[i].x), cnt += sign(tmp - a.x) > 0;//交点在A右方
}
return cnt & 1;//穿过奇数次则在多边形以内
}
inline int judge_PP(Point *A, int n, Point *B, int m) {//【判断多边形A与多边形B是否相离】
for (int i1 = 1; i1 <= n; ++i1) {
int j1 = i1 < n ? i1 + 1 : 1;
for (int i2 = 1; i2 <= m; ++i2) {
int j2 = i2 < m ? i2 + 1 : 1;
if (pan_cross_SS(A[i1], A[j1], B[i2], B[j2]))return 0;//两线段相交
if (PIP(B, m, A[i1]) || PIP(A, n, B[i2]))return 0;//点包含在内
}
}
return 1;
}
inline bool pan_ALR(Point A, Point L, Point R) {//判断AL在AR严格左侧
return sign(Cro(L - A, R - A)) < 0;
}
int n, m;
Point p[N], A, B, O;
ld r = 0;
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
p[i].in();
}
for (int i = 1; i <= m; ++i) {
A.in(), B.in();
O = A + B;
O.x /= 2, O.y /= 2;
r = Len(A - B) / 2;
if (PIP(p, n, O)) {
printf("%.10Lf\n", r * r / 2);
continue;
}
ld mn = 1e100;
for (int j = 1; j <= n; ++j) {
mn = min(mn, dis_PS(O, p[j], p[j == n ? 1 : j + 1]));
}
mn = S(r) / 2 + S(mn);
printf("%.10Lf\n", mn);
}
}
signed main() {
int T = 1;
// cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 6912kb
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: 0
Accepted
time: 2ms
memory: 7072kb
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.3942307692 287.3850000000 689.6250000000 436.2500000000
result:
ok Your answer is acceptable!^ ^
Test #3:
score: 0
Accepted
time: 380ms
memory: 7072kb
input:
5000 5000 -50000000 0 -49999885 -49450 -49999770 -85675 -49999604 -122394 -49999391 -157604 -49999130 -192731 -49998803 -229143 -49998399 -267196 -49997956 -303872 -49997469 -339362 -49996891 -377221 -49996257 -414903 -49995577 -451819 -49994843 -488600 -49994059 -524941 -49993173 -563137 -49992252 ...
output:
2214785369560632.8750000000 1632645104370924.3748779297 3954739966640761.3752441406 5405105667896787.7500000000 817274719687553.0313720703 902260846427661.0824584961 3194363161448624.1250000000 1619744446324385.1248779297 363457485421825.2499694824 4776425533214308.6240234375 8267595460255072.723144...
result:
ok Your answer is acceptable!^ ^
Test #4:
score: 0
Accepted
time: 211ms
memory: 6948kb
input:
2224 5000 -500000 0 -499999 -30 -499998 -59 -499997 -87 -499996 -114 -499995 -140 -499994 -165 -499993 -189 -499992 -212 -499991 -234 -499990 -255 -499989 -275 -499988 -294 -499987 -312 -499986 -329 -499985 -345 -499984 -360 -499982 -389 -499981 -403 -499979 -430 -499978 -443 -499976 -468 -499975 -4...
output:
931340796015.3750000596 410570465847.7500000000 225774975043.7500000000 686588110927.3750000000 803635163394.8750000000 440321806244.7499999702 781364862674.5000000596 303496624306.7500000000 146653887864.7500000000 1361017661096.7500000000 409649028457.5000000000 417747460932.7500000000 46509181005...
result:
ok Your answer is acceptable!^ ^
Test #5:
score: -100
Wrong Answer
time: 211ms
memory: 7020kb
input:
4672 5000 -300 0 -299 -43 -298 -85 -297 -126 -296 -166 -295 -205 -294 -243 -293 -280 -292 -316 -291 -351 -290 -385 -289 -418 -288 -450 -287 -481 -286 -511 -285 -540 -284 -568 -283 -595 -282 -621 -281 -646 -280 -670 -279 -693 -278 -715 -276 -758 -275 -779 -273 -820 -272 -840 -270 -879 -269 -898 -267 ...
output:
356616.5000000000 121018.5000000000 0.2500000000 189.6250000000 103099.6250000000 83253.1250000000 131701.2500000000 58352.5000000000 355863.1250000000 197638.8597240473 605772.4121621622 2062.4458977408 113763.2500000000 134694.5000000000 74679.6520547945 114481.2500000000 60577.2500000000 7456.250...
result:
wrong answer Except 57754.614864864903, but found 7183.125000000000!QAQ