Poj2060taxi cab Scheme (Bipartite Graph Matching)

Source: Internet
Author: User
1/* 2 meaning: There is a departure time for a taxi. The time ranges from (a, B) To (c, d). The time is 3 Abs (a-c) + ABS (B-d )! A car can transport another passenger after one passenger is completed. The four conditions are that the car will arrive at the departure location one minute before the reservation starts. Ask the minimum number of vehicles required. 5. Get all the reservations. 6 7. Train of Thought: Create a graph with a directed edge, because the start time is in ascending order! 8 T0: (A0, B0)-> (C0, D0) indicates that the reservation starts from (a, B) To (c, d) at t0 time ); // node x 9 T1: (A1, B1)-> (C1, D1) indicates that the reservation starts from (A1, B1) to (C1, D1) at T1 ); // node y 10 11 if possible, after the Vehicle departing from t0 arrives at the destination, if it is satisfied from (c, d) to (A1, B1) 12, that is, the time from the first destination to the next departure location T2 + 1 <= T1, so no other car is needed again! Both appointments have been completed! 14 If yes, create a directed edge between node X and node y! 15 finally, the Hungary algorithm is used to solve the problem ..... 16 */17 # include <iostream> 18 # include <cmath> 19 # include <cstdio> 20 # include <cstring> 21 # include <algorithm> 22 # include <vector> 23 # define M 50524 using namespace STD; 25 26 struct point {27 int X, Y; 28 point () {} 29 point (int x, int y) {30 this-> X = X; 31 This-> Y = y; 32} 33 int operator-(point a) {34 return ABS (x-a.x) + ABS (y-a.y); 35} 36 }; 37 38 struct node {39 40 int begin, end; 41 point S, D; 42}; 43 44 node Nd [m]; 45 vector <int> V [m]; 46 int vis [m]; 47 int link [m]; 48 49 int N; 50 51 bool DFS (INT cur) {52 int Len = V [cur]. size (); 53 for (INT I = 0; I <Len; ++ I) {54 int u = V [cur] [I]; 55 if (vis [u]) continue; 56 vis [u] = 1; 57 if (! Link [u] | DFS (link [u]) {58 link [u] = cur; 59 return true; 60} 61} 62 Return false; 63} 64 65 int main () {66 int t; 67 scanf ("% d", & T); 68 while (t --) {69 70 scanf ("% d", & N); 71 for (INT I = 1; I <= N; ++ I) {72 int B, E, X1, y1, X2, Y2; 73 scanf ("% d: % d", & B, & E, & X1, & Y1, & X2, & Y2); 74 Nd [I]. begin = B * 60 + E; 75 Nd [I]. S = point (x1, Y1); 76 Nd [I]. D = point (X2, Y2); 77 Nd [I]. end = Nd [I]. begin + (Nd [I]. s-Nd [I]. d); 78} 79 for (INT I = 1; I <n; ++ I) 80 for (Int J = I + 1; j <= N; ++ J) {81 If (Nd [J]. begin> = Nd [I]. end + (Nd [I]. d-Nd [J]. s) + 1) // if you can meet the conditions that you love to reach another departure location, create a directed edge between the two nodes: 82 V [I]. push_back (j); 83} 84 int ans = 0; 85 memset (link, 0, sizeof (Link); 86 for (INT I = 1; I <= N; ++ I) {87 memset (VIS, 0, sizeof (VIS); 88 If (DFS (I) ++ ans; 89} 90 cout <n-ans <Endl; 91 for (INT I = 1; I <= N; ++ I) 92 V [I]. clear (); 93} 94 return 0; 95}

 

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.