QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#556814#8082. Minimum Euclidean DistanceJinTianHaoTL 0ms3824kbC++171.9kb2024-09-10 21:10:182024-09-10 21:10:19

Judging History

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

  • [2024-09-10 21:10:19]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3824kb
  • [2024-09-10 21:10:18]
  • 提交

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-10;
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);
			double dis=sqrtl((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
			double l=0,r=dis;
			while(r-l>eps)
			{
				double lmid=(2*l+r)/3,rmid=(l+2*r)/3;
				double ld=(x[i]+(x[j]-x[i])/dis*lmid-xc)*(x[i]+(x[j]-x[i])/dis*lmid-xc)+(y[i]+(y[j]-y[i])/dis*lmid-yc)*(y[i]+(y[j]-y[i])/dis*lmid-yc);
				double rd=(x[i]+(x[j]-x[i])/dis*rmid-xc)*(x[i]+(x[j]-x[i])/dis*rmid-xc)+(y[i]+(y[j]-y[i])/dis*rmid-yc)*(y[i]+(y[j]-y[i])/dis*rmid-yc);
				mn=min({mn,ld,rd});
				if(ld<rd) r=rmid;
				else l=lmid;
			}
		}
		printf("%.10lf\n",mn+((xc-xa)*(xc-xa)+(yc-ya)*(yc-ya))/2);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: -100
Time Limit Exceeded

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.5000000000
1632645104370924.0000000000
3954739966640761.0000000000
5405105667896787.0000000000
817274719687553.0000000000
902260846427661.0000000000
3194363161448624.0000000000
1619744446324385.0000000000
363457485421825.2500000000
4776425533214308.0000000000
8287234924912337.000000...

result: