This is the shortest distance between the two convex packets,
In fact, you only need to find "the current vector area is not smaller than the next vector area,
If this condition is met, the current two ymin and Ymax vertices are the opposite vertices.
The Code is as follows. For more information, see:
# Include <cmath> # include <cstdio> # include <iostream> using namespace STD; typedef struct {float X, Y ;}dot; dot operator-(dot a, dot B) {dot c = {. x-b.x,. y-b.y}; return C;} float operator * (dot a, dot B) {return. x * B. y-b.x *. y;} float operator/(dot a, dot B) {return. x * B. X +. y * B. y;} // indicates whether the vertex is in the float DIS (dot a, dot B) {return SQRT (POW (. x-b.x, 2) + POW (. y-b.y, 2);} float DTL (dot a, dot B, dot c) // The shortest distance from point C to line AB {If (( B-A)/(c-a) <0) return DIS (C, A); If (a-B)/(c-B) <0) return DIS (C, B); Return FABS (a-B) * (C-B)/DIS (A, B);} float LTL (dot, dot B, dot C, dot d) {return min (DTL (A, B, C), DTL (a, B, d), min (DTL (C, d, a), DTL (c, d, B);} float work (DOT * a, dot * B, int N, int m) {dot t; float ans = 1e9; int I, ymin = 0, Ymax = 0; for (I = 0; I <n; I ++) if (a [I]. Y <A [ymin]. y) ymin = I; for (I = 0; I <m; I ++) if (B [I]. y> B [Ymax]. y) Ymax = I; A [n] = A [0]; B [m] = B [0]; for (I = 0; I <N; I ++) {T = A [ymin + 1]-A [ymin]; while (T * (B [Ymax]-A [ymin]) <t * (B [Ymax + 1]-A [ymin]) // locate the area of the current vector not less than the area of the next vector. Then Ymax = (Ymax + 1) % m; ans = min (ANS, LTL (A [ymin], a [ymin + 1], B [Ymax], B [Ymax + 1]); ymin = (ymin + 1) % N;} return ans;} int main () {int I, n, m; dot a [10010], B [10010]; while (scanf ("% d", & N, & M) & n! = 0 | M! = 0) {for (I = 0; I <n; I ++) scanf ("% F", & A [I]. x, & A [I]. y); // The single precision runs fast and the precision is 1e-6. For this question, it is enough for (I = 0; I <m; I ++) scanf ("% F", & B [I]. x, & B [I]. y); printf ("%. 3f \ n ", work (A, B, n, m); // It is enough if the precision is in 1e-3 }}
Rotating jamming solution poj3608bridge sans SS islands