QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#485744 | #8082. Minimum Euclidean Distance | zttttt | AC ✓ | 144ms | 4140kb | C++23 | 5.2kb | 2024-07-21 03:52:35 | 2024-07-21 03:52:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=5010;
double aa[N],bb[N],cc[N];
pair<double,double>p[N];
//struct S}{
// int x1,y1,x2,y1;
//}s[N];
double xx[N],yy[N];
signed main(){
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>p[i].first>>p[i].second;
}
for(int i=2;i<=n;i++){
xx[i]=p[i].first-p[i-1].first;
}
xx[1]=p[1].first-p[n].first;
//for(int i=1;i<=n;i++)cout<<i<<" "<<xx[i]<<endl;
for(int i=2;i<=n;i++){
yy[i]=p[i].second-p[i-1].second;
}
yy[1]=p[1].second-p[n].second;
//for(int i=1;i<=n;i++)cout<<i<<" "<<yy[i]<<endl;
for(int i=2;i<=n;i++){
aa[i]=p[i].second-p[i-1].second;
bb[i]=p[i-1].first-p[i].first;
cc[i]=p[i].first*p[i-1].second-p[i-1].first*p[i].second;
}
aa[1]=p[1].second-p[n].second;
bb[1]=p[n].first-p[1].first;
cc[1]=p[1].first*p[n].second-p[n].first*p[1].second;
// for(int i=2;i<=n;i++){
// bb[i]=p[i-1].second-xl[i]*p[i-1].first;
// }
// bb[1]=p[n].second-xl[1]*p[n].first;
for(int i=1;i<=q;i++){
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
double r=0.5*sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
// if(fabs(0.5*r*r-7183.125)<1e-6){
// cout<<r<<endl;
// continue;
// }
//cout<<r<<endl;
double yxx=(x1+x2)*0.5;
//cout<<yxx<<endl;
double yxy=(y1+y2)*0.5;
//cout<<yxy<<endl;
int cntl=0,cntz=0,cntf=0;
for(int j=1;j<n;j++){
double xlx=yxx-p[j].first;
// cout<<j<<" "<<p[j].first<<endl;
// cout<<j<<" "<<yxx<<endl;
// cout<<j<<" "<<xlx<<endl;
double xly=yxy-p[j].second;
double cj=xx[j+1]*xly-yy[j+1]*xlx;
// cout<<j<<" "<<cj<<endl;
if(cj<0){
cntf++;
}else if(cj>0){
cntz++;
}else{
if(yxx>=min(p[j].first,p[j+1].first)&&yxx<=max(p[j].first,p[j+1].first)&&yxy>=min(p[j].second,p[j+1].second)&&yxy<=max(p[j].second,p[j+1].second))cntl++;
}
}
//cout<<cntf<<" "<<cntl<<" "<<cntz<<endl;
double xlx=yxx-p[n].first;
double xly=yxy-p[n].second;
double cj=xx[1]*xly-yy[1]*xlx;
if(cj<0){
cntf++;
}else if(cj>0){
cntz++;
}else{
if(yxx>=min(p[1].first,p[n].first)&&yxx<=max(p[1].first,p[n].first)&&yxy>=min(p[1].second,p[n].second)&&yxy<=max(p[1].second,p[n].second))cntl++;
}
if(cntl>0){
// if(fabs(0.5*r*r-7183.125)<1e-6){
// cout<<r<<endl;
// continue;
// }
cout<<fixed<<setprecision(9);
cout<<0.5*r*r<<endl;
}else if(cntz==n){
cout<<fixed<<setprecision(9);
cout<<0.5*r*r<<endl;
}else{
double jl=100000000000000;
// for(int j=1;j<=n;j++){
// jl=min(jl,sqrt((yxx-p[j].first)*(yxx-p[j].first)+(yxy-p[j].second)*(yxy-p[j].second)));
// }
// for(int j=1;j<=n;j++){
// jl=min(jl,)
// }
int flag=0;
for(int j=2;j<=n;j++){
double aaa=bb[j],bbb=-aa[j];
double ccc=aa[j]*yxy-bb[j]*yxx;
double jdx=1.0*(-cc[j]*bbb+bb[j]*ccc)/(aa[j]*bbb-bb[j]*aaa);
double jdy=1.0*(aa[j]*(-ccc)+cc[j]*aaa)/(aa[j]*bbb-bb[j]*aaa);
//cout<<j<<" "<<jdx<<endl;
// if(fabs(sqrt((yxx-jdx)*(yxx-jdx)+(yxy-jdy)*(yxy-jdy))-1946708139892914)<1e-6){
// cout<<yxx<<" "<<yxy<<" "<<p[j-1].first<<" "<<p[j-1].second<<" "<<p[j].first<<" "<<p[j].second<<" "<<jdx<<" "<<jdy<<endl;
// flag=1;
// }
if((jdx>min(p[j-1].first,p[j].first)||fabs(jdx-min(p[j-1].first,p[j].first))<1e-6)&&(jdx<max(p[j-1].first,p[j].first)||fabs(jdx-max(p[j-1].first,p[j].first))<1e-6)&&(jdy>min(p[j-1].second,p[j].second)||fabs(jdy-min(p[j-1].second,p[j].second))<1e-6)&&(jdy<max(p[j-1].second,p[j].second)||fabs(jdy-max(p[j-1].second,p[j].second))<1e-6)){
jl=min(jl,sqrt((yxx-jdx)*(yxx-jdx)+(yxy-jdy)*(yxy-jdy)));
// if(fabs(jl-1946966666535562.75)<1e-6){
// cout<<yxx<<" "<<yxy<<" "<<p[j-1].first<<" "<<p[j-1].second<<" "<<p[j].first<<" "<<p[j].second<<" "<<jdx<<" "<<jdy<<endl;
// flag=1;
// break;
// }
}
}
if(flag)continue;
double aaa=bb[1],bbb=-aa[1];
double ccc=aa[1]*yxy-bb[1]*yxx;
double jdx=1.0*(-cc[1]*bbb+bb[1]*ccc)/(aa[1]*bbb-bb[1]*aaa);
double jdy=1.0*(aa[1]*(-ccc)+cc[1]*aaa)/(aa[1]*bbb-bb[1]*aaa);
// if(fabs(sqrt((yxx-jdx)*(yxx-jdx)+(yxy-jdy)*(yxy-jdy))-1946708139892914)<1e-6){
// cout<<0<<endl;
// flag=1;
// }
if((jdx>min(p[1].first,p[n].first)||fabs(jdx-min(p[1].first,p[n].first))<1e-6)&&(jdx<max(p[1].first,p[n].first)||fabs(jdx-max(p[1].first,p[n].first))<1e-6)&&(jdy>min(p[1].second,p[n].second)||fabs(jdy-min(p[1].second,p[n].second))<1e-6)&&(jdy<max(p[1].second,p[n].second)||fabs(jdy-max(p[1].second,p[n].second))<1e-6)){
jl=min(jl,sqrt((yxx-jdx)*(yxx-jdx)+(yxy-jdy)*(yxy-jdy)));
// if(fabs(jl-1946966666535562.75)<1e-6){
// cout<<0<<endl;
// flag=1;
// break;
// }
}
if(flag)continue;
//cout<<jl<<endl;
for(int i=1;i<=n;i++){
jl=min(jl,sqrt((yxx-p[i].first)*(yxx-p[i].first)+(yxy-p[i].second)*(yxy-p[i].second)));
}
// if(fabs(0.5*r*r+jl*jl-1946966666535993)<1e-6){
// cout<<0.5*r*r<<endl;
// continue;
// }
cout<<0.5*r*r+jl*jl<<endl;
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3680kb
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.250000000 0.750000000 1.875000000
result:
ok Your answer is acceptable!^ ^
Test #2:
score: 0
Accepted
time: 0ms
memory: 3872kb
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.5 51.4706 1051.250000000 66.625000000 174.125000000 562.675000000 272.394230769 287.385000000 689.625000000 436.250000000
result:
ok Your answer is acceptable!^ ^
Test #3:
score: 0
Accepted
time: 126ms
memory: 3924kb
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:
2.21479e+15 1.63265e+15 3.95474e+15 5.40511e+15 8.17275e+14 9.02261e+14 3194363161448624.000000000 1619744446324385.000000000 363457485421825.187500000 4776425533214309.000000000 8267595460255074.000000000 2467163193204921.500000000 1182580285938702.250000000 1785755073284987.000000000 2070106793477...
result:
ok Your answer is acceptable!^ ^
Test #4:
score: 0
Accepted
time: 68ms
memory: 4044kb
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:
9.31341e+11 4.1057e+11 2.25775e+11 6.86588e+11 8.03635e+11 4.40322e+11 7.81365e+11 3.03497e+11 1.46654e+11 1.36102e+12 4.09649e+11 4.17747e+11 4.65092e+11 1.43637e+12 5.0074e+11 1.94108e+11 4.06051e+11 8.7219e+11 9.08392e+11 7.53546e+11 2.55035e+11 6.94698e+11 8.0031e+11 9.34837e+11 1.06886e+12 4.85...
result:
ok Your answer is acceptable!^ ^
Test #5:
score: 0
Accepted
time: 68ms
memory: 4120kb
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.500000000 121018.500000000 0.250000000 189.625000000 103099.625000000 83253.125000000 131701.250000000 58352.500000000 355863.125000000 197638.859724047 605772.412162162 2062.445897741 113763.250000000 134694.500000000 74679.652054795 114481.250000000 60577.250000000 7456.250000000 44460.2500...
result:
ok Your answer is acceptable!^ ^
Test #6:
score: 0
Accepted
time: 16ms
memory: 3908kb
input:
576 5000 -300 0 -299 -15 -298 -29 -297 -42 -296 -54 -295 -65 -294 -75 -293 -84 -292 -92 -290 -107 -289 -114 -287 -127 -286 -133 -284 -144 -283 -149 -280 -163 -278 -172 -275 -185 -274 -189 -270 -204 -267 -215 -265 -222 -262 -232 -258 -245 -257 -248 -252 -262 -248 -273 -245 -281 -240 -294 -238 -299 -2...
output:
189295.250000000 377943.294416244 299473.000000000 243821.917197452 559270.992227979 100367.592339667 472743.125000000 374450.625000000 77260.625000000 106891.230769231 193578.125000000 98895.065414508 124020.000000000 296138.875000000 1209.125000000 480040.625000000 133543.970689655 194311.00000000...
result:
ok Your answer is acceptable!^ ^
Test #7:
score: 0
Accepted
time: 9ms
memory: 3888kb
input:
336 5000 -300 0 -299 -11 -298 -21 -297 -30 -296 -38 -295 -45 -294 -51 -292 -62 -291 -67 -289 -76 -288 -80 -285 -91 -283 -98 -280 -108 -279 -111 -275 -122 -272 -130 -270 -135 -267 -142 -263 -151 -258 -162 -257 -164 -251 -175 -246 -184 -242 -191 -239 -196 -234 -204 -227 -215 -225 -218 -218 -228 -213 -...
output:
478.125000000 408.125000000 1341.250000000 861.250000000 4210.000000000 1709.125000000 846.250000000 1389.125000000 722.500000000 753.125000000 574.250000000 1167.125000000 439.625000000 5650.250000000 619.625000000 2664.500000000 2138.625000000 2138.625000000 1226.250000000 1226.250000000 702.12500...
result:
ok Your answer is acceptable!^ ^
Test #8:
score: 0
Accepted
time: 7ms
memory: 3892kb
input:
336 5000 -300 0 -299 -11 -298 -21 -297 -30 -296 -38 -295 -45 -294 -51 -292 -62 -291 -67 -289 -76 -288 -80 -285 -91 -283 -98 -280 -108 -279 -111 -275 -122 -272 -130 -270 -135 -267 -142 -263 -151 -258 -162 -257 -164 -251 -175 -246 -184 -242 -191 -239 -196 -234 -204 -227 -215 -225 -218 -218 -228 -213 -...
output:
95.125000000 8382.625000000 77361.125000000 142408.125000000 98056.250000000 110581.250000000 20413.000000000 1253.125000000 64468.625000000 8915.625000000 93179.125000000 26286.250000000 35118.250000000 129681.250000000 59545.625000000 49997.910377358 1685.125000000 58020.625000000 38372.000000000 ...
result:
ok Your answer is acceptable!^ ^
Test #9:
score: 0
Accepted
time: 138ms
memory: 4112kb
input:
5000 5000 -50000000 0 -49999912 -33572 -49999824 -59400 -49999710 -83347 -49999578 -105149 -49999382 -130924 -49999166 -154591 -49998916 -178069 -49998599 -203894 -49998262 -228398 -49997905 -251647 -49997466 -277451 -49997003 -302413 -49996511 -326907 -49995964 -352128 -49995393 -376671 -49994795 -...
output:
4.81991e+17 9.00047e+17 8.42502e+16 3.57963e+17 7.58025e+17 6.51806e+17 4.22072e+17 5.71949e+17 6.85947e+17 7.81018e+17 3.92639e+17 3.60254e+17 4.2753e+17 5.66636e+17 3.38832e+17 5.3236e+17 1.15572e+18 1.95132e+17 8.7048e+17 3.98751e+17 6.49986e+17 3.74853e+17 8.6731e+16 4.14286e+17 5.40991e+17 9.66...
result:
ok Your answer is acceptable!^ ^
Test #10:
score: 0
Accepted
time: 144ms
memory: 4140kb
input:
5000 5000 -50000000 0 -49999762 -138397 -49999461 -244153 -49999007 -349713 -49998392 -456086 -49997577 -566637 -49996632 -673023 -49995462 -784273 -49994137 -894156 -49992625 -1005080 -49990945 -1115094 -49989066 -1226720 -49987021 -1337531 -49984788 -1449227 -49982415 -1559155 -49979887 -1668061 -...
output:
2.59053e+17 4.72298e+17 2.71977e+17 9.30649e+17 1.10596e+17 3.85964e+17 4.41659e+17 2.59108e+17 3.79724e+17 4.3294e+16 2.75916e+17 5.4197e+17 5.71201e+17 4.99015e+17 1.18411e+18 2.65941e+17 3.1263e+17 1.03423e+18 2.66324e+17 8.23164e+17 2.26488e+17 8.25618e+17 4.09062e+17 5.23207e+17 8.44629e+17 1.7...
result:
ok Your answer is acceptable!^ ^
Extra Test:
score: 0
Extra Test Passed