QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#441863#7846. Glacier TravelA_zjzjAC ✓4ms8332kbC++171.5kb2024-06-14 20:06:292024-06-14 20:06:29

Judging History

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

  • [2024-06-14 20:06:29]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:8332kb
  • [2024-06-14 20:06:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned ll;
using ld=long double;
using vec=complex<ld>;
const int N=1e6+10;
int n;
double m;
vec a[N];
ld dot(const vec &a,const vec &b){
	return real(a)*real(b)+imag(a)*imag(b);
}
ld cross(const vec &a,const vec &b){
	return dot(a,b*vec(0,-1));
}
ld dis(const vec &a){
	return sqrtl(dot(a,a));
}
ld pre[N];
pair<ld,int>t[N+N];
const ld eps=1e-11;
vec find(ld k){
	int l=1,r=n,mid;
	for(;l+1<r;){
		mid=(l+r)>>1;
		if(pre[mid]-eps<k)l=mid;
		else r=mid;
	}
	vec arg=a[r]-a[l];
	return a[l]+arg/dis(arg)*(k-pre[l]);
}
int main(){
	scanf("%lf%d",&m,&n);
	for(int i=1,x,y;i<=n;i++){
		scanf("%d%d",&x,&y),a[i]=vec(x,y);
	}
	for(int i=2;i<=n;i++){
		pre[i]=pre[i-1]+dis(a[i]-a[i-1]);
	}
	for(int i=1;i<=n;i++){
		t[i]={pre[i],i},t[i+n]={pre[i]+m,-i};
	}
	inplace_merge(t+1,t+1+n,t+1+n+n);
	ld ans=INFINITY;
	for(int i=1,x=0,y=0;i<=n+n;i++){
		auto [d,id]=t[i];
		if(id>0)x=id;
		else y=-id;
		if(max(x,y)>=n)break;
		if(!x||!y)continue;
		vec a=find(d)-find(d-m);
		vec b=find(get<0>(t[i+1]))-find(get<0>(t[i+1])-m);
		if(dot(a,b)>0)ans=min({ans,dis(a),dis(b)});
		else ans=min(ans,abs(cross(a,b))/dis(a-b));
	}
	printf("%.9Lf\n",ans);
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

详细

Test #1:

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

input:

5
4
20 0
10 0
10 10
0 10

output:

3.535533906

result:

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

Test #2:

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

input:

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

output:

1.000000000

result:

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

Test #3:

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

input:

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

output:

2.293595760

result:

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

Test #4:

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

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.000000000

result:

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

Test #5:

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

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.344214437

result:

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

Test #6:

score: 0
Accepted
time: 3ms
memory: 6548kb

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.044504744

result:

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

Test #7:

score: 0
Accepted
time: 4ms
memory: 8332kb

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.038185710

result:

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

Test #8:

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

input:

40
3
100 0
0 100
0 0

output:

15.307337295

result:

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

Test #9:

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

input:

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

output:

0.000000000

result:

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