Hdu1350 solution Report-minimum edge coverage

Source: Internet
Author: User

A taxi company has M appointments, and each reservation occupies one line: (for example) a B c d (a, B) indicates the starting point of the reservation. (c, d) indicates the end of the task. The previous time is the start time, and the end time of the task is | a-c | + | B-d | + start time, so for the M booking, how many vehicles can be dispatched at least? Analysis: At first, I thought of the Time Scheduling Problem in the greedy algorithm, but later I found an error. Here we should use the minimum edge coverage of binary matching. The minimum edge coverage is as follows: minimum path overwrite = | P |-Maximum number of matches (| P | a specified number of points) the method for finding the maximum number of matches is to divide each vertex pi in P into two vertex pi 'and pj ''. If there is a side of pi to pj in p, in the bipartite plot P, there is a undirected edge connecting pi 'and pj ''. Here pi' is the outbound edge of pi in p, pj ''is an inbound edge of pj in p. For the formula: Minimum path overwrite = | P |-Maximum number of matches, this can be understood. If the number of matches is zero, therefore, P does not have a directed edge, so it is clear that it has: Minimum path overwrite = | P |-Maximum number of matches = | P |-0 = | P |; that is, the minimum number of path overwrites of P |; the number of path overwrites when the P is not in the matching edge | P |; if a matched edge pi '--> pj ''is added to P, an edge connecting pj by pi exists in the path overwrite of P, that is to say, pi and pj are in one path, so the number of path overwrites can be reduced. One; then we can solve it like this: if we regard all the tasks as points, if we can still complete the j tasks after completing the I tasks, we will add an edge I --> j, it is worth noting that when I can complete j after computing is completed, we should make the following judgment condition: [cpp] if (node [I]. st> = node [j]. end + 1 + abs (node [I]. a-node [j]. c) + abs (node [I]. b-node [j]. d) {add (I, j);} The Judgment condition is interpreted as: to complete the I-th task, our location is (node [I]. c, node [I]. d) at this location, the start time for us to arrive at task j is [cpp] abs (node [I]. a-node [j]. c) + abs (node [I]. b-node [j]. d) the entire question will be analyzed. Mount the question: [cpp] // 265 MS 996 K # include <stdio. h> # Include <math. h> # include <string. h> # define MAX 505 int N; struct Node {int st, end; int a, B, c, d;} node [MAX]; struct Edge {int, nxet;} edge [MAX * MAX]; int head [MAX], tol; void add (int a, int B) {edge [tol]. to = B; edge [tol]. nxet = head [a]; head [a] = tol ++;} int link [MAX], vis [MAX]; bool dfs (int u) {for (int j = head [u]; j! =-1; j = edge [j]. nxet) {int v = edge [j]. to; if (vis [v]) continue; vis [v] = true; if (link [v] =-1 | dfs (link [v]) {link [v] = u; return true;} return false;} int match () {int ans = 0; memset (link,-1, sizeof (link )); for (int I = 1; I <= N; I ++) {memset (vis, 0, sizeof (vis); if (dfs (I )) ans ++;} return ans;} int main () {int T; int h, m; scanf ("% d", & T); while (T --) {tol = 0; memset (head,-1, sizeof (head); scanf ("% d", & N); for (int I = 1; I <= N; I ++) {scanf ("% d: % d", & h, & m); scanf ("% d ", & node [I]. a, & node [I]. b, & node [I]. c, & node [I]. d); node [I]. st = h * 60 + m; node [I]. end = node [I]. st + abs (node [I]. a-node [I]. c) + abs (node [I]. b-node [I]. d); for (int j = I-1; j> 0; j --) {if (node [I]. st> = node [j]. end + 1 + abs (node [I]. a-node [j]. c) + abs (node [I]. b-node [j]. d) {add (I, j) ;}} printf ("% d \ n", N-match () ;}return 0 ;} personal ignorance, thank you for your correction and discussion.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.