Submission #742202

# Submission time Handle Problem Language Result Execution time Memory
742202 2023-05-15T18:53:01 Z rainboy Experiments with Gorlum (IZhO13_expgorl) C
Compilation error
0 ms 0 KB
#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.c: In function 'main':
expgorl.c:25:2: warning: ignoring return value of 'scanf' 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;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccLphIaU.o: in function `main':
expgorl.c:(.text.startup+0x191): undefined reference to `hypot'
/usr/bin/ld: expgorl.c:(.text.startup+0x1d2): undefined reference to `hypot'
/usr/bin/ld: expgorl.c:(.text.startup+0x2b4): undefined reference to `hypot'
/usr/bin/ld: expgorl.c:(.text.startup+0x2f8): undefined reference to `hypot'
collect2: error: ld returned 1 exit status