#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 10005;
const double INF = 1E18 + 7;
struct SPoint
{
int x, y;
} g[N], o;
int k, n, dx, dy;
double mi, ma;
char s[N];
double dist(const SPoint &a, int iter)
{
return hypot(1.0 * dx * iter + a.x - o.x, 1.0 * 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%d %d\n%d %d", &k, s + 1, &g[0].x, &g[0].y, &o.x, &o.y);
n = strlen(s + 1);
mi = ma = hypot(g[0].x - o.x, g[0].y - o.y);
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%d %d\n%d %d", &k, s + 1, &g[0].x, &g[0].y, &o.x, &o.y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |