Uvalive 2523 Machine Schedule (binary graph for maximum number of matches)

Source: Internet
Author: User

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)

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.