Machine Schedule 赤裸裸的二分匹配 二部图中的点覆盖书==匹配数

                    Machine Schedule

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <string>
 7 #include <vector>
 8 #include <set>
 9 #include <map>
10 #include <stack>
11 #include <queue>
12 #include <sstream>
13 #include <iomanip>
14 using namespace std;
15 typedef long long LL;
16 const int INF = 0x4fffffff;
17 const double EXP = 1e-5;
18 const int MS = 105;
19 const int SIZE = 100005;
20
21 // data struct
22 int edges[MS][MS];
23 int cx[MS],cy[MS];
24 int mark[MS];
25
26 int n,m,k;
27
28 int path(int u)
29 {
30      for(int v=1;v<m;v++)
31      {
32            if(edges[u][v]&&!mark[v])
33            {
34                  mark[v]=1;
35                  if(cy[v]==-1||path(cy[v]))
36                  {
37                        cx[u]=v;
38                        cy[v]=u;
39                        return 1;
40                  }
41            }
42      }
43      return 0;
44 }
45
46 void match()
47 {
48       int ans=0;
49       memset(cx,0xff,sizeof(cx));
50       memset(cy,0xff,sizeof(cy));
51       for(int u=1;u<n;u++)
52       {
53             if(cx[u]==-1)
54             {
55                   memset(mark,0,sizeof(mark));
56                   ans+=path(u);
57             }
58       }
59       printf("%d\n",ans);
60 }
61
62
63 int main()
64 {
65       while(scanf("%d",&n)&&n)
66       {
67             scanf("%d%d",&m,&k);
68             memset(edges,0,sizeof(edges));
69             int t,u,v;
70             for(int i=0;i<k;i++)
71             {
72                   scanf("%d%d%d",&t,&u,&v);
73                   if(u!=0&&v!=0)
74                   {
75                         edges[u][v]=1;
76                   }
77             }
78             match();
79       }
80       return 0;
81 }
时间: 2024-08-26 05:28:10

Machine Schedule 赤裸裸的二分匹配 二部图中的点覆盖书==匹配数的相关文章

HDU 1150:Machine Schedule(二分匹配,匈牙利算法)

Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5371    Accepted Submission(s): 2658 Problem Description As we all know, machine scheduling is a very classical problem in compu

HDU 1150 Machine Schedule (二分匹配)

Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduli

hdu 1150 Machine Schedule (经典二分匹配)

//A组n人 B组m人 //最多有多少人匹配 每人仅仅有匹配一次 # include<stdio.h> # include<string.h> # include<algorithm> using namespace std; int n,m,k; int pp[1100][1100],map[1100],vis[1100]; int bfs(int x)//二分匹配模板 { for(int i=1;i<=m;i++)//B组中的人来迎合匹配 { if(!vis[

hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6733    Accepted Submission(s): 3375 Problem Description As we all know, mach

杭电 HDU ACM 1150 Machine Schedule(二分匹配)

Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7056    Accepted Submission(s): 3537 Problem Description As we all know, machine scheduling is a very classical problem in compu

LA 3126 二分匹配---DAG中的最小路径应用

题意:有 n 个顾客 , 需要坐出租车从一个地方去另一个地方 , 每个顾客的出发时间.出发地点.目的地点都已给出 , 从出发地点到目的地点的时间为两地之间的路径长度 , 并且出租车要比顾客的出发时间早一分钟到达 , 问最少需要派出多少辆出租车. 解法:我们先这样来构图 , 每个顾客是一个结点,如果同一个出租车在接完客人 u 之后还来得及节客人 v , 那么就在 u 到 v 之间连一条有向边 . 由此可以发现 , 这个图是一个DAG , 那么我们就只需要找最小路径覆盖(最小路径覆盖:是指在图中找尽

Poj1325 Machine Schedule 最大二分图匹配 匈牙利算法

Machine Schedule Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied an

hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1150 Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history.

POJ1325 Machine Schedule 【二分图最小顶点覆盖】

Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11958   Accepted: 5094 Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduli