#include <bits/stdc++.h>
using namespace std;
long long m,n,k,s1,t1,s2,t2,vx=0,vy=0;
double minn=1e15,maxn=0;
char s[10005];
double Dist(long long u1,long long v1,long long u2,long long v2)
{
return sqrt((u1-u2)*(u1-u2)+(v1-v2)*(v1-v2));
}
double Ternary(long long x,long long y,long long r)
{
long long l=0;
double rs=1e15;
while(l<=r)
{
long long m1=l+(r-l)/3;
long long m2=r-(r-l)/3;
double tmp1=Dist(x+m1*vx,y+m1*vy,s2,t2);
double tmp2=Dist(x+m2*vx,y+m2*vy,s2,t2);
rs=min(rs,min(tmp1,tmp2));
if(tmp1<tmp2)
r=m2-1;
else
l=m1+1;
}
return rs;
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
//freopen("TEST.OUT","w",stdout);
cin>>k>>s+1>>s2>>t2>>s1>>t1;
n=strlen(s+1);
for(long long i=1;i<=n;i++)
{
if(s[i]=='L')
vx--;
if(s[i]=='R')
vx++;
if(s[i]=='B')
vy--;
if(s[i]=='F')
vy++;
}
minn=min(minn,Ternary(s1,t1,k));
maxn=max(maxn,max(Dist(s1,t1,s2,t2),Dist(s1+k*vx,t1+k*vy,s2,t2)));
for(long long i=1;i<=n;i++)
{
if(s[i]=='L')
s1--;
if(s[i]=='R')
s1++;
if(s[i]=='B')
t1--;
if(s[i]=='F')
t1++;
minn=min(minn,Ternary(s1,t1,k-1));
maxn=max(maxn,max(Dist(s1,t1,s2,t2),Dist(s1+(k-1)*vx,t1+(k-1)*vy,s2,t2)));
}
cout<<setprecision(10)<<fixed<<minn<<' '<<maxn;
}
Compilation message
expgorl.cpp: In function 'int main()':
expgorl.cpp:37:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
cin>>k>>s+1>>s2>>t2>>s1>>t1;
~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
428 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
4 ms |
564 KB |
Output is correct |
11 |
Correct |
3 ms |
564 KB |
Output is correct |
12 |
Correct |
4 ms |
672 KB |
Output is correct |
13 |
Correct |
4 ms |
672 KB |
Output is correct |
14 |
Correct |
4 ms |
672 KB |
Output is correct |
15 |
Correct |
4 ms |
672 KB |
Output is correct |
16 |
Correct |
4 ms |
672 KB |
Output is correct |
17 |
Correct |
4 ms |
672 KB |
Output is correct |
18 |
Correct |
5 ms |
672 KB |
Output is correct |
19 |
Correct |
4 ms |
672 KB |
Output is correct |
20 |
Correct |
4 ms |
672 KB |
Output is correct |