QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#556833#8082. Minimum Euclidean DistanceJinTianHaoWA 163ms3996kbC++172.0kb2024-09-10 21:19:342024-09-10 21:19:35

Judging History

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

  • [2024-09-10 21:19:35]
  • 评测
  • 测评结果:WA
  • 用时:163ms
  • 内存:3996kb
  • [2024-09-10 21:19:34]
  • 提交

answer

#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
// #define int long long
// #pragma GCC optimize("Ofast","inline","-ffast-math")
// #pragma GCC target("avx,sse2,sse3,sse4,mmx")
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
const double eps=1e-7;
int n,q;
int x[5005],y[5005];
signed main()
{
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	read(n);read(q);
	for(int i=1;i<=n;++i)
		read(x[i]),read(y[i]);
	while(q--)
	{
		int xa,ya,xb,yb;
		read(xa);read(ya);read(xb);read(yb);
		double xc=(xa+xb)/2.0,yc=(ya+yb)/2.0;
		int fh=0;
		bool inch=1;
		for(int i=1;i<=n;++i)
		{
			int j=(i<n?i+1:1);
			double s=(x[i]-xc)*(y[j]-yc)-(x[j]-xc)*(y[i]-yc);
			if(fabs(s)<eps) fh=-1;
			if(fh==1&&s<-eps) inch=0;
			if(fh==-1&&s>eps) inch=0;
			if(fh==0) fh=(s>eps?1:s<-eps?-1:0);
		}
		if(inch)
		{
			printf("%.10lf\n",((xc-xa)*(xc-xa)+(yc-ya)*(yc-ya))/2);
			continue;
		}
		double mn=1e18;
		for(int i=1;i<=n;++i)
		{
			int j=(i<n?i+1:1);
			mn=min(mn,(x[i]-xc)*(x[i]-xc)+(y[i]-yc)*(y[i]-yc));
			mn=min(mn,(x[j]-xc)*(x[j]-xc)+(y[j]-yc)*(y[j]-yc));
			if(x[i]==x[j])
			{
				if(yc>min(y[i],y[j])-eps&&yc<max(y[i],y[j])+eps)
					mn=min(mn,(xc-x[i])*(xc-x[i]));
				continue;
			}
			if(y[i]==y[j])
			{
				if(xc>min(x[i],x[j])-eps&&xc<max(x[i],x[j])+eps)
					mn=min(mn,(yc-y[i])*(yc-y[i]));
				continue;
			}
			double k=(y[i]-y[j])*1.0/(x[i]-x[j]);
			double kk=-1/k;
			double b=y[i]-k*x[i],bb=yc-kk*xc;
			double xx=(b-bb)/(kk-k),yy=k*xx+b;
			if(xx>min(x[i],x[j])-eps&&xx<max(x[i],x[j])+eps)
				mn=min(mn,(xc-xx)*(xc-xx)+(yc-yy)*(yc-yy));
		}
		printf("%.10lf\n",mn+((xc-xa)*(xc-xa)+(yc-ya)*(yc-ya))/2);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3972kb

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: 0ms
memory: 3900kb

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: 163ms
memory: 3996kb

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:

2214785369560633.0000000000
1632645104370924.5000000000
3954739966640761.0000000000
5405105667896787.0000000000
817274719687553.0000000000
902260846427661.1250000000
3194363161448624.0000000000
1619744446324385.0000000000
363457485421825.2500000000
4776425533214308.0000000000
8267595460255073.000000...

result:

ok Your answer is acceptable!^ ^

Test #4:

score: 0
Accepted
time: 86ms
memory: 3920kb

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.3750000000
410570465847.7500000000
225774975043.7500000000
686588110927.3750000000
803635163394.8750000000
440321806244.7500000000
781364862674.5000000000
303496624306.7500000000
146653887864.7500000000
1361017661096.7500000000
409649028457.5000000000
417747460932.7500000000
46509181005...

result:

ok Your answer is acceptable!^ ^

Test #5:

score: 0
Accepted
time: 89ms
memory: 3820kb

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.4121621621
2062.4458977408
113763.2500000000
134694.5000000000
74679.6520547945
114481.2500000000
60577.2500000000
7456.250...

result:

ok Your answer is acceptable!^ ^

Test #6:

score: -100
Wrong Answer
time: 15ms
memory: 3784kb

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.2500000000
377943.2944162436
299473.0000000000
243821.9171974522
559270.9922279792
100367.5923396675
472743.1250000000
374450.6250000000
77260.6250000000
106891.2307692308
193578.1250000000
98895.0654145078
124020.0000000000
296138.8750000000
1209.1250000000
480040.6250000000
133543.970689655...

result:

wrong answer Except 148835.204152249091, but found 136890.000000000000!QAQ