#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 10005;
const double INF = 1E18 + 7;
struct SPoint
{
long long x, y;
} g[N], o;
int k, n;
long long dx, dy;
char s[N];
double dist(const SPoint &a, int iter)
{
return hypot(dx * iter + a.x - o.x, dy * iter + a.y - o.y);
}
double TS(const SPoint &a)
{
double ret = INF;
int l = 0, r = k - 1;
while (r - l >= 3)
{
int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
double d1 = dist(a, m1), d2 = dist(a, m2);
ret = min(ret, min(d1, d2));
if (d1 > d2)
l = m1;
else
r = m2;
}
for (; l <= r; l++)
ret = min(ret, dist(a, l));
return ret;
}
int main()
{
scanf("%d\n%s\n%lld %lld\n%lld %lld", &k, s + 1, &g[0].x, &g[0].y, &o.x, &o.y);
n = strlen(s + 1);
double mi = dist(g[0], 0), ma = dist(g[0], 0);
for (int i = 1; i <= n; i++)
switch (s[i])
{
case 'L':
g[i] = (SPoint){g[i - 1].x - 1, g[i - 1].y};
break;
case 'R':
g[i] = (SPoint){g[i - 1].x + 1, g[i - 1].y};
break;
case 'F':
g[i] = (SPoint){g[i - 1].x, g[i - 1].y + 1};
break;
case 'B':
g[i] = (SPoint){g[i - 1].x, g[i - 1].y - 1};
break;
case 'I':
g[i] = (SPoint){g[i - 1].x, g[i - 1].y};
break;
}
dx = g[n].x - g[0].x; dy = g[n].y - g[0].y;
for (int i = 1; i <= n; i++)
{
ma = max(ma, max(dist(g[i], 0), dist(g[i], k - 1)));
mi = min(mi, TS(g[i]));
}
printf("%.16f %.16f\n", mi, ma);
}
Compilation message
expgorl.cpp: In function 'int main()':
expgorl.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d\n%s\n%lld %lld\n%lld %lld", &k, s + 1, &g[0].x, &g[0].y, &o.x, &o.y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |