HDU 1350 Taxi Cab Scheme (binary match)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1350

Taxi Cab SchemeTime limit:20000/10000 MS (java/others) Memory limit:65536/32768 K (java/others) Total Submission (s): 943 Accepted Submission (s): 456

Problem descriptionrunning A taxi station isn't all, simple. Apart from the obvious demand for a centralised coordination of the cabs in order to pick up the customers calling to get A cab as soon as possible, there is also a need to schedule all the taxi rides which has been booked in advance. Given a list of all booked taxi rides for the next day, you want to minimise the number of cabs needed to carry off all of The rides.

For the sake of simplicity, we model a city as a rectangular grid. An address in the city was denoted by the Integers:the Street and Avenue number. The time needed to get from the address A, B to C, d by Taxi is |a-c| + |b-d| Minutes. A cab may carry out a booked ride if it's it's first ride of the day, or if it can get to the source address of the new RI De from it latest, at least one minute before the new ride ' s scheduled departure. Note that some rides may end after midnight.

Inputon the first line of the input was a single positive an integer N, telling the number of the test scenarios to follow. Each scenario begins with a line containing an integer M, 0 < M <, being the number of booked taxi rides. The following M lines contain the rides. Each ride was described by a departure time on the format hh:mm (ranging from 00:00 to 23:59), and the other integers a b that was th e coordinates of the source address and integers C d that is the coordinates of the destination address. All coordinates is at least 0 and strictly smaller than 200. The booked rides in each scenario is sorted in order of increasing departure time.

Outputfor each scenario, output one line containing the minimum number of cabs required to carry out all the booked taxi R Ides.

Sample Input
2,208:00 10 11 9 1608:07 9 16 10 11,208:00 10 11 9 1608:06 9 16 10 11

Sample Output
12

Sourcenorthwestern Europe 2004
recommendjgshining | We have carefully selected several similar problems for you:1054 1083 1528 1287 1507 the main idea: a straightforward explanation of the first set of data: First enter an n, indicating that there are several people to ride, Next n rows, each line is entered: time, start position coordinates, target position coordinates

According to the above data and requirements, output the minimum number of drivers required.

Problem-solving ideas: start to see this topic first idea is greedy, directly to reach the target location time and the next person's starting time comparison. But do not find the minimum number of drivers to be able to get. We should use the minimum side coverage of the binary matching, the minimum path overrides the =|n|-maximum match number (n is the fixed number)

Concrete implementation: treat each person's coordinates as a point. If the first driver receives a customer and then receives B, he or she will be connected to an edge. And the least driver to cover all points. The perfect transformation ~ ~ ~

Special attention:

1, the time to send passengers to Harman distance, the formula is |a-c| + |b-d|

2. One minute interval is required for each transfer, so don't forget to add 1


See the code.

#include <iostream> #include <cstdio> #include <cstring>using namespace std;struct node{int Stime,eti Me,sx,sy,ex,ey;} P[510];int map[510][510];int n;int ok[510],vis[510];int Fun (int a) {return a<0?-a:a;} BOOL Find (int x) {for (int i=0; i<n; i++) {if (Map[x][i]==1&&!vis[i]) {vis[i]=            1;                if (ok[i]==-1) {ok[i]=x;            return true;                    } else {if (Find (Ok[i])) {ok[i]=x;                return true; }}}} return false;}    int main () {int t;            while (~SCANF ("%d", &t)) {while (t--) {memset (ok,-1,sizeof (OK));            int q,w,a,b,c,d;            scanf ("%d", &n);                for (int i=0; i<n; i++) {scanf ("%d:%d%d%d%d%d", &q,&w,&a,&b,&c,&d); int l=q*60+w;               P[i].stime=l;                P[i].sx=a;                P[i].sy=b;                P[i].ex=c;                P[i].ey=d;            P[i].etime=fun (a-c) +fun (b-d);                    } for (int i=0, i<n; i++) {for (int j=i+1; j<n; J + +) {                        if (P[i].stime+p[i].etime+fun (P[I].EX-P[J].SX) +fun (p[i].ey-p[j].sy) +1<=p[j].stime) {                    Map[i][j]=1;                } else map[i][j]=0;            }} int k=0;                for (int i=0;i<n;i++) {memset (vis,0,sizeof (VIS));            if (Find (i)) k++;        } printf ("%d\n", n-k); }} return 0;}



HDU 1350 Taxi Cab Scheme (binary match)

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.