Puppy walking
Grant enjoys walking with his puppy pandog. Grant takes a fixed route at a certain speed, which may be self-routed. Pandog prefers to visit the scenic spots along the way, but will meet the host at the given n points. The puppy and the master start from (x1, Y1) and join at (Xn, yn. The puppy is twice as fast as grant. When the host goes straight from one point to another, pandog runs to an interesting attraction. Pandog can only go to one scenic spot at most before each meeting with the host.
Your current task is to find a route for pandog (which may be the same as the main route) so that it can visit the most scenic spots, and can meet or join the host at a given place on time.
Input
The first line of the input file is two integers, N and M (1 ≤ n, m ≤ 100 );
The N coordinates of the second line of the input file provide the walking route of grant, that is, the location where pandog and the host meet;
The m coordinates in the third line of the input file show all the scenic spots that interest pandog.
All input coordinates are different, and the absolute value cannot exceed 1000.
Output
Output the route of the puppy.
The first line is the number of points passed by, and the second line is the coordinates of the points passed by (Cartesian coordinate system)
Sample Input
4 5
1 4 5 7 5 2-2 4
-4-2 3 9 1 2-1 3 8-3
Sample output
6
1 4 3 9 5 7 5 2 1 2-2 4
Hit: the answer is not necessarily unique.
/* <Br/> question: see the above; </P> <p> question: If you directly consider the route of a puppy, each time you reach a new meeting point, take action plans for puppies into consideration. The total calculation workload is P (m, n) exponential complexity algorithms are undoubtedly inefficient and impractical. <Br/>: Because "when the host goes straight from one point to another, pandog runs to an interesting attraction", and the director's mobile route is determined, <br/>: Therefore, finding a route can be used to determine the choice of a puppy on each route: the scenic spot to which the puppy runs, or the overlapping route of the Director. Obviously, if each segment of the owner's movement is abstracted as a point, <br/>: its nature is different from that of the puppy's desired scenic spot. Therefore, the points in the figure are naturally divided into two categories, and the question requires the relationship between the two categories. <Br/>: because a puppy can only run to one scenic spot on a line segment, whether the Scenic Spot is accessible depends only on the distance between the scenic spot and the two ends of the line segment. <Br/>: because a line segment can only be associated with one scenic spot, and one scenic spot is only meaningful during the first visit, no intersection exists between the two links, this clearly satisfies the definition of matching. <Br/>: the two types of Fixed Points form a bipartite graph, and the maximum matching of the two points set of the target ball is achieved. </P> <p> */<br/> # include <iostream> <br/> # include <cmath> <br/> using namespace STD; </P> <p> # define maxn 110 </P> <p> struct node <br/> {<br/> int X, Y; <br/>} X [maxn], Y [maxn]; </P> <p> int map [maxn] [maxn]; <br/> int B [maxn], Match [maxn]; <br/> bool vis [maxn]; <br/> int n, m; </P> <p> double DIS (node X, node y) <br/> {<br/> return SQRT (ABS (X. x-y.x) * ABS (X. x-y.x) + ABS (X. y-y.y) * ABS (X. y-y.y); <br/>}</P> <p> bool DFS (int I) <br/ >{< Br/> Int J, CNT; <br/> for (j = 1; j <= n-1; j ++) <br/> {<br/> // J = map [I] [CNT]; <br/> // cout <I <": "<j <Endl; <br/> If (! Vis [J] & map [I] [J]) {<br/> vis [J] = 1; <br/> If (Match [J] = 0 | DFS (Match [J]) <br/>{< br/> match [J] = I; <br/> return true; <br/>}< br/> return false; <br/>}< br/> int main () <br/> {<br/> freopen ("230.txt"," r ", stdin ); <br/> int I, j, k; <br/> while (scanf ("% d", & N, & M )! = EOF) <br/>{< br/> for (I = 1; I <= N; I ++) <br/> scanf ("% d ", & X [I]. x, & X [I]. y); <br/> for (j = 1; j <= m; j ++) <br/> scanf ("% d ", & Y [J]. x, & Y [J]. y); <br/> memset (B, 0, sizeof (B); <br/> memset (MAP, 0, sizeof (MAP )); <br/> for (I = 1; I <= n-1; I ++) <br/> {<br/> for (j = 1; j <= m; j ++) <br/>{< br/> // cout <(DIS (X [I], Y [J]) + DIS (Y [J], X [I + 1])/2 <Endl; <br/> If (DIS (X [I], X [I + 1])> (DIS (X [I], Y [J]) + DIS (Y [J], X [I + 1])/2) <br/> {<br/> map [J] [I] = 1; <Br/> // cout <I <":" <j <Endl; </P> <p >}< br/> int ans = 0; <br/> memset (match, 0, sizeof (MATCH); <br/> for (I = 1; I <= m; I ++) <br/>{< br/> memset (VIS, 0, sizeof (VIS); <br/> If (DFS (I) <br/>{< br/> ans ++; <br/>}< br/> printf ("% d/N", ANS + n); <br/> for (I = 1; I <= N; I ++) <br/> {<br/> printf ("% d", X [I]. x, X [I]. y); <br/> if (I = N) {printf ("/N ");} <br/> else <br/> {<br/> printf (""); <br/> If (Match [I]! = 0) <br/> printf ("% d", Y [Match [I]. x, Y [Match [I]. y); <br/>}< br/> return 0; <br/>}< br/>