Hdu 1350 Taxi Cab Scheme (minimum overwrite)

Source: Internet
Author: User

Based on the meaning of this question, we can create a picture. For two booked taxi ride, ri and rj, if a car can complete the task of ri first, then it will be time to complete the task of rj, then an edge pointing to rj is created.

Select the least taxi to complete these tasks according to the requirements of the questions. Obviously, in the above example, two taxi vehicles are required. In combination with this diagram, we can convert the requirements of the question into finding the minimum number of paths so that these paths overwrite all the edges on the way, for example, you can select 2 paths 1-> 3-> 4 and 1-> 2 to overwrite all edges. You can also select 1-> 3-> 4 and 2 (because 2 is the initial station, it does not need to be transferred from 1 ). For a continuous path vi1-> vi2->... Vik because the task on this path is actually completed by a taxi, it can be degraded into two vertices vi1-> vik. After the two steps of graph creation, the problem can be solved to find a minimum subset of the vertex set, make this vertex subset overwrite all edges (each edge is connected to at least the vertex of a vertex set ). This problem is the minimum vertex coverage of the graph. Looking at this image, there are some other properties that allow us to better find the minimum point coverage. This graph is a directed acyclic graph. Without a self-ring graph, you can split the point and convert the original graph into a bipartite graph.


We can see from the figure that the preceding Path 1-> 3-> 4 corresponds to the Path 1-> 3'-> 3-> 4' in the bipartite graph ', in this bipartite graph, a maximum independent subset is required (here the four points are the end point of a path, and no path corresponds to an end point !). The maximum number of independence in a bipartite graph is the difference between the total number of points and the maximum number of matching. Next, create a graph, split the points, and find the maximum matching of the Bipartite Graph to solve this problem.


First, enter a time, the corresponding time when a car is driving, then the start point (x1, y1), and then the end point (x2, y2 ), start to End Time is | x1-x2 | + | y1-y2 |, suppose that the start time, the time on the way, and the time from the first vehicle to the start of the second car are less than the start time of the second car, that means you don't have to dispatch another car.
[Csharp]
# Include "stdio. h"
# Include "string. h"
# Include "stdlib. h"
# Include "math. h"
Int map [501] [501], mark [501], link [501], v [501];
Int n, m;
Char time [10];
Struct node
{
Int x1, x2, y1, y2;
Int t, sum;
} Aa [1, 501];
Int fun (int x1, int y1, int x2, int y2)
{
Return abs (x1-x2) + abs (y1-y2 );
}
Int dfs (int k)
{
Int I;
For (I = 0; I <m; I ++)
{
If (map [k] [I] &! V [I])
{
V [I] = 1;
If (link [I] =-1 | dfs (link [I])
{
Link [I] = k;
Return 1;
}
}
}
Return 0;
}
Int main ()
{
Int I, j, ans;
Scanf ("% d", & n );
While (n --)
{
Scanf ("% d", & m );
For (I = 0; I <m; I ++)
{
Scanf ("% s", time );
Scanf ("% d", & aa [I]. x1, & aa [I]. y1, & aa [I]. x2, & aa [I]. y2 );
Aa [I]. t = (time [0]-'0') * 10*60 + (time [1]-'0') * 60
+ (Time [3]-'0') * 10 + (time [4]-'0 ');
Aa [I]. sum = fun (aa [I]. x1, aa [I]. y1, aa [I]. x2, aa [I]. y2 );
}
Memset (map, 0, sizeof (map ));
For (I = 0; I <m-1; I ++)
{
For (j = I + 1; j <m; j ++)
{
If (aa [I]. t + aa [I]. sum + fun (aa [I]. x2, aa [I]. y2, aa [j]. x1, aa [j]. y1) <aa [j]. t)
Map [I] [j] = 1;
}
}
Ans = 0;
Memset (link,-1, sizeof (link ));
For (I = 0; I <m; I ++)
{
Memset (v, 0, sizeof (v ));
Ans + = dfs (I );
}
Printf ("% d \ n", m-ans );
}
Return 0;
}

Author: yyf572132811

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.