QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#485741#8082. Minimum Euclidean DistanceztttttWA 119ms4244kbC++234.8kb2024-07-21 03:44:072024-07-21 03:44:07

Judging History

你现在查看的是最新测评结果

  • [2024-07-21 03:44:07]
  • 评测
  • 测评结果:WA
  • 用时:119ms
  • 内存:4244kb
  • [2024-07-21 03:44:07]
  • 提交

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<<0<<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{
				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{
				cntl++;
			}
		if(cntl>0){
			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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3900kb

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: 3836kb

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: 119ms
memory: 4244kb

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: 67ms
memory: 4000kb

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: -100
Wrong Answer
time: 67ms
memory: 4204kb

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:

wrong answer Except 57754.614864864903, but found 0.000000000000!QAQ