Topic Link: UVA 503-parallelepiped walk
Nausea problem, will three-dimensional turn into two-dimensional, straight line distance shortest, WA a day. Assuming that the starting point is on the ground, it is possible to consider the arrival of two faces in addition to considering the possibility of 0 or 1 polygons. A code that generates data is provided later.
#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;typedef long ll; CONST LL inf = 0x3f3f3f3f3f3f3f3f;struct Point {ll x, y; Point (ll x = 0, ll y = 0): x (x), Y (y) {}};ll Dis (point A, point B) {ll x = a.x-b.x;ll y = a.y-b.y;return x * x + y * Y;} ll solve (int L, int W, int H, int x1, int y1, int z1, int x2, int y2, int z2) {ll ans = inf;if (x2 = = 0) {ans = min (ans, Dis (Point (x1, y1), point (-z2, y2))); ans = min (ans, dis (point (x1, y1), point (Y2-w, z2+w))); ans = min (ans, dis (x1, y1) , point (-y2,-z2))); ans = min (ans, dis (point (x1, y1), point (Z2-h, 2*w+h-y2))); ans = min (ans, dis (x1, y1), point (z2-h ,-(H+y2))));} if (x2 = = L) {ans = min (ans, dis (x1, y1), point (l+z2, y2))); ans = min (ans, dis (point (x1, y1), point (L+w-y2, z2+w))); ans = min (ans, dis (x1, y1), point (L+y2,-z2)), ans = min (ans, dis (point (x1, y1), point (L+H-Z2,-(H+Y2)))); ans = min ( Ans, Dis (Point (x1, y1), point (L+H-Z2, 2*w+h-y2)));} if (z2 = = 0) {ans = min (ans, Dis (Point (x1, y1), point (x2, y2)));} if (z2 = = H) {ans = min (ans, dis (x1, y1), point (-(H+X2), y2))); ans = min (ans, dis (point (x1, y1), point (-(H+y2),-x2) ); ans = min (ans, dis (point (x1, y1), point (-(W+h-y2), w+x2))); ans = min (ans, dis (x1, y1), point (2*l+h-x2, y2)); ans = min (ans, dis (x1, y1), point (L+w+h-y2, l+w-x2)); ans = min (ans, dis (point (x1, y1), point (L+h+y2, x2-l))); ans = min ( ans, dis (point (x1, y1), point (L+h+x2, 2*w+l-y2))); ans = min (ans, dis (point (x1, y1), point (l+h+x2,-(L+Y2))));} return ans;} int main () {int L, W, H, x1, y1, Z1, x2, Y2, Z2;while (scanf ("%d%d%d%d%d%d%d%d%d", &l, &w, &h, &x1, & Y1, &z1, &x2, &y2, &z2) = = 9) {ll ans = inf;for (int i = 0; i < 2; i++) {if (x1 = = 0) {ans = min (ans, s Olve (W, H, L, Y1, Z1, X1, y2, Z2, x2)); ans = min (ans, solve (H, W, L, Z1, Y1, X1, Z2, Y2, x2));} else if (x1 = = L) {ans = min (ans, solve (W, H, L, Y1, Z1, l-x1, Y2, Z2, l-x2)); ans = min (ans, solve (H, W, L, Z1, Y1, l-x1, Z2, Y2, l-x2));} else if (y1 = = 0) {ans = min (ans, solve (L, H, W, X1, z1, Y1, x2, Z2, y2)); ans = min (ans, solve (H, L, W, Z1, x1, y1, Z2, x2 , y2));} else if (y1 = = W) {ans = min (ans, solve (L, H, W, X1, Z1, w-y1, X2, Z2, w-y2)); ans = min (ans, solve (H, L, W, Z1, X1, W-y1, Z2, x2, W-y2));} else if (z1 = = 0) {ans = min (ans, solve (L, W, H, x1, y1, Z1, x2, Y2, Z2)); ans = min (ans, solve (w, L, H, Y1, X1, z1, Y2, x2 , Z2));} else if (z1 = = H) {ans = min (ans, solve (L, W, H, x1, y1, h-z1, x2, y2, h-z2)); ans = min (ans, solve (w, L, H, Y1, X1, H-Z1, Y2, x2, h-z2));} Swap (X1,X2), swap (Y1, y2), swap (z1, Z2);} printf ("%lld\n", ans);} return 0;} /* Data *//*using namespace Std;const int D = 1000;int Main () {int cas = 1000;while (cas--) {int l[3]; L[0] = rand ()% d + 1, l[1] = rand ()% d + 1, l[2] = rand ()% d + 1;printf ("%d%d", l[0], l[1], l[2]); for (int i = 0; I < 2; i++) {int k = rand ()% 3;for (int j = 0; J < 3; J + +) {if (k = = j) printf ("%d", (cas&1) L[J]: 0); elseprintf ("%d", rand ()% l[j] + 1);}} PriNTF ("\ n");} return 0;} */
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVA 503-parallelepiped Walk (geometry)