Test instructions: There are two machines, there are several working areas, there are several tasks, can be completed in one area of two machines, two machines start in 0 areas, each change area, will be restarted once, let us find the minimum number of restarts.
Idea: Connect two areas, use a binary map, find the maximum number of matches, easy to understand, just the minimum number of restarts.
Note: 01 has been completed at the beginning and should not be added to the matching sequence.
The code is as follows:
#include <iostream>#include<algorithm>#include<queue>#include<cstdio>#include<cstring>using namespacestd;#defineN 110intMaps[n][n],n,m,match[n],vis[n];BOOLFind (intx) { for(inti =1; I <= m; i++) { if(Maps[x][i] &&!Vis[i]) {Vis[i]=1; if(match[i]==-1||Find (Match[i])) {Match[i]=x; return true; } } } return false;}inthungry () {memset (match,-1,sizeof(match)); intAns =0; for(inti =1; I <= N; i++) {memset (Vis,0,sizeof(VIS)); if(Find (i)) ans++; } returnans;}intMain () {inta,b,c,k; //freopen ("G.in.cpp", "R", stdin); while(~SCANF ("%d",&N)) {if(!n) Break; scanf ("%d%d",&m,&k); memset (Maps,0,sizeof(maps)); for(inti =0; I < K; i++) {scanf ("%d%d%d",&a,&b,&c); if(b>0&& c>0) Maps[b][c]=1; } printf ("%d\n", Hungry ()); } return 0;}
Uvalive 2523Machine Schedule (binary graph for maximum number of matches)