#include <math.h>
#include <stdio.h>
#include <string.h>
#define N 10000
#define INF 1e12
double min(double a, double b) { return a < b ? a : b; }
double max(double a, double b) { return a > b ? a : b; }
long long dot2(int x1, int y1, int x2, int y2) {
return (long long) x1 * x2 + (long long) y1 * y2;
}
long long dot(int x0, int y0, int x1, int y1, int x2, int y2) {
return dot2(x1 - x0, y1 - y0, x2 - x0, y2 - y0);
}
int main() {
static char cc[N + 1];
static int xx[N + 1], yy[N + 1];
int n, k, k_, i, x1, y1, x2, y2, x, y, x_, y_;
double d, mn, mx;
scanf("%d%s%d%d%d%d", &k, cc, &x1, &y1, &x2, &y2), n = strlen(cc), x_ = x2 - x1, y_ = y2 - y1;
x = y = 0;
for (i = 0; i <= n; i++) {
if (cc[i] == 'L')
x--;
if (cc[i] == 'R')
x++;
if (cc[i] == 'B')
y--;
if (cc[i] == 'F')
y++;
xx[i + 1] = x, yy[i + 1] = y;
}
mn = INF, mx = 0;
for (i = 0; i <= n; i++) {
x1 = xx[i], y1 = yy[i], x2 = xx[i] + xx[n] * (k - 1), y2 = yy[i] + yy[n] * (k - 1);
d = hypot(x_ + x1, y_ + y1);
mn = min(mn, d), mx = max(mx, d);
d = hypot(x_ + x2, y_ + y2);
mn = min(mn, d), mx = max(mx, d);
if (dot(x1, y1, x2, y2, 0, 0) > 0 && dot(x2, y2, x1, y1, 0, 0) > 0) {
k_ = dot2(0 - x1, 0 - y1, xx[n], yy[n]) / dot2(xx[n], yy[n], xx[n], yy[n]);
d = hypot(x_ + x1 + xx[n] * k_, y_ + y1 + yy[n] * k_);
mn = min(mn, d);
d = hypot(x_ + x1 + xx[n] * (k_ + 1), y_ + y1 + yy[n] * (k_ + 1));
mn = min(mn, d);
}
}
printf("%.12f %.12f\n", mn, mx);
return 0;
}
Compilation message
expgorl.cpp: In function 'int main()':
expgorl.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%d%s%d%d%d%d", &k, cc, &x1, &y1, &x2, &y2), n = strlen(cc), x_ = x2 - x1, y_ = y2 - y1;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |