QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#270765#7846. Glacier TravelRedcrown#AC ✓1ms8072kbC++171.9kb2023-12-01 13:50:042023-12-01 13:50:05

Judging History

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

  • [2023-12-01 13:50:05]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:8072kb
  • [2023-12-01 13:50:04]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ssz(x) ((int)x.size())
using namespace std;
const int N=1e6+5,eps=1e-4;
int n,m;
inline int red(){
	int data=0;bool w=0;char ch=getchar();
	while(ch!='-' && (ch<'0' || ch>'9'))ch=getchar();
	if(ch=='-') w=1,ch=getchar();
	while(ch>='0' && ch<='9') data=(data<<3)+(data<<1)+ch-'0',ch=getchar();
	return w?-data:data;
}
double len[N];
int x[N],y[N];
double s;
double dis(double x,double y){
	return x*x+y*y;
}
double ans=1000;
void calc(int l, int r, double nowl, double nowr, double det)
{
	if(det < eps) return;
	double vx1=x[l+1]-x[l],vy1=y[l+1]-y[l],vx2=x[r+1]-x[r],vy2=y[r+1]-y[r];
	double x1=x[l]+vx1*nowl/len[l],y1=y[l]+vy1*nowl/len[l];
	double x2=x[l]+vx1*(nowl+det)/len[l],y2=y[l]+vy1*(nowl+det)/len[l];
	double x3=x[r]+vx2*nowr/len[r],y3=y[r]+vy2*nowr/len[r];
	double x4=x[r]+vx2*(nowr+det)/len[r],y4=y[r]+vy2*(nowr+det)/len[r];
	x2 = x2-x1; y2 = y2-y1; x4 = x4-x3; y4 = y4-y3;
	double a=dis(x2-x4,y2-y4), b=2*((x2-x4)*(x1-x3)+(y2-y4)*(y1-y3)), c=dis(x1-x3,y1-y3);
	ans = min(ans,c); ans = min(ans,a+b+c);
	double s0 = -b/(2*a);
	if(s0 >= 0 && s0 <= 1) ans = min(ans,a*s0*s0+b*s0+c);
	//printf("nowans: %.9f\n",ans);
}
void solve(){
	scanf("%lf%d",&s,&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x[i],&y[i]);
	}
	for(int i=1;i<n;i++){
		len[i]=dis(x[i]-x[i+1],y[i]-y[i+1]);
		len[i] = sqrt(len[i]);
	}
	int l=1,r=1;
	double nowl=0,nowr=s;
	while(r<n&&nowr>=len[r]){
		nowr-=len[r];
		r++;
	}
	while(r<n){
		double det=min(len[l]-nowl,len[r]-nowr);
		calc(l,r,nowl,nowr,det);
		nowl+=det;
		nowr+=det;
		//printf("now: %d %d %.7f %.7f %.7f\n",l,r,nowl,nowr,det);
		if(nowl+eps>=len[l])nowl=0,l++;
		if(nowr+eps>=len[r])nowr=0,r++;
		//if(det < 1e-4) break;
	}
	printf("%.8f",sqrt(ans));
}
int main()
{
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	//cout.tie(0); 
	int T=1;
	while(T--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
4
20 0
10 0
10 10
0 10

output:

3.53553391

result:

ok found '3.53553', expected '3.53553', error '0.00000'

Test #2:

score: 0
Accepted
time: 1ms
memory: 8064kb

input:

3.16227766
9
-2 4
2 4
3 1
4 4
5 1
6 4
10 2
6 1
7 4

output:

1.00000000

result:

ok found '1.00000', expected '1.00000', error '0.00000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 8016kb

input:

20
5
9 38
36 16
-5 36
-24 15
30 37

output:

2.29359576

result:

ok found '2.29360', expected '2.29360', error '0.00000'

Test #4:

score: 0
Accepted
time: 1ms
memory: 7968kb

input:

10
40
17 18
12 -5
12 -16
-10 16
7 -15
18 -18
19 15
-19 1
-18 11
-8 -12
-17 -12
5 -12
-15 -8
-10 -10
-4 4
-2 -3
15 17
-2 -9
-13 7
-12 17
15 -3
-19 -14
6 6
14 -5
-10 -15
17 -16
-11 15
9 -6
10 8
19 -1
12 -6
-18 2
14 17
9 -7
-8 -3
7 11
-12 -14
-19 4
-1 15
-17 16

output:

0.00000000

result:

ok found '0.00000', expected '0.00000', error '-0.00000'

Test #5:

score: 0
Accepted
time: 1ms
memory: 8072kb

input:

10
40
10 11
11 15
6 -16
-18 4
10 10
-10 16
-17 11
2 6
-6 -9
17 -7
-7 -5
10 -18
-9 9
-14 10
19 -3
-14 -3
15 -5
-3 16
-10 14
-9 -12
10 -18
10 -4
-9 -11
11 -2
9 2
12 15
2 -17
-8 -16
19 7
-19 -2
-17 7
16 -9
6 -6
8 -18
15 9
17 2
-19 12
-15 -9
1 -15
19 -12

output:

0.34421444

result:

ok found '0.34421', expected '0.34421', error '0.00000'

Test #6:

score: 0
Accepted
time: 1ms
memory: 8032kb

input:

1000
4000
-720538 -681604
667325 347504
-911397 -962007
-264075 -858319
49605 149209
964851 361021
-397274 28661
-460607 -273701
104862 -136807
-803899 -693703
-974 -337735
323678 -209811
-745617 -358684
-984333 603546
722843 -444579
701511 -255784
-676477 -836480
998942 -227888
-502059 -438394
9641...

output:

0.04450474

result:

ok found '0.04450', expected '0.04450', error '0.00000'

Test #7:

score: 0
Accepted
time: 0ms
memory: 8028kb

input:

1000
4000
703 909
500 496
-214 628
914 -44
-330 -238
-1424 -1426
347 1420
332 -1417
877 1678
-1390 819
-921 525
121 -923
-851 -859
512 -151
765 -109
416 -1529
-269 667
475 -234
-708 300
1917 -1935
-909 1342
1141 -696
-272 1295
1908 -1124
-898 -1225
1608 630
-1937 1246
-255 1021
-1005 -1650
-1595 -39...

output:

0.03818571

result:

ok found '0.03819', expected '0.03819', error '0.00000'

Test #8:

score: 0
Accepted
time: 0ms
memory: 8064kb

input:

40
3
100 0
0 100
0 0

output:

15.30733729

result:

ok found '15.30734', expected '15.30734', error '0.00000'

Test #9:

score: 0
Accepted
time: 1ms
memory: 7972kb

input:

48.2842712475
4
-10 -10
10 10
-10 10
10 -10

output:

0.00000024

result:

ok found '0.00000', expected '0.00000', error '0.00000'