"Network flow 24 questions" with pilots (pilot pairing scheme problem)

Source: Internet
Author: User

"Description of the problem" the flight brigade has several drivers from all over the world who specialize in one type of aircraft, each of which has two pilots and requires a positive driver and a co-pilot. For a variety of reasons, such as co-ordination, some pilots cannot fly on the same plane and ask how to match the driver to make the most of the flight. , assuming that there are 10 drivers, the V1,V2,...,V10 represents up to 10 drivers, of which V1,V2,V3,V4,V5 is the pilot, and V6,V7,V8,V9,V10 is the co-pilot. If a pilot and a co-pilot can fly on the same plane, on behalf of both of them a line between the two, two people can not fly with the aircraft, it is not connected. For example, V1 and V7 can fly on the same plane, while V1 and V8 do not. Please match the pilot to make the most of the aircraft sailing. Note: Because the driving division is strict, two pilots or two copilot cannot fly with each other. The input format input file has several lines
The first line, two integers n and N1, indicates a total of n pilots (2<=N<=100), including N1 pilots.
There are several lines below, each with 2 numbers, A, B. Indicates that both driver A and copilot B can fly on the same machine. Note: The pilot's number is before the driver's number is less than the pilot's number. Output format output file has one line
The first line, 1 integers, indicates the maximum number of aircraft to take off. Input Output Sample input file name: 10 5
1 7
2 6
2 10
3 7
4 8
5 9 Output File name: 4
"Analysis" began to do the network flow 24, this is the first problem, the Hungarian algorithm naked question, of course, can also network flow do, I wrote Hungary.
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <algorithm>6#include <queue>7 using namespacestd;8 #defineMAXN 11009 Ten structnode One { A     intX,y,next; -}T[MAXN];intLen; - intFIRST[MAXN]; the  - voidInsintXinty) - { -t[++len].x=x;t[len].y=y; +t[len].next=first[x];first[x]=Len; - } +  A intM,n; at  - intMATCH[MAXN]; - BOOLCHW[MAXN]; - BOOLFfind (intx) - { -     //printf ("%d\n", x); in      for(intI=first[x];i;i=t[i].next)if(!Chw[t[i].y]) -     { to         inty=t[i].y; +chw[y]=1; -         //printf ("%d\n", x); the         if(!match[y]| |Ffind (Match[y])) *         { $match[y]=x;Panax Notoginseng             return 1; -         } the     } +     return 0; A } the  + intans; - voidSolve () $ { $memset (Match,0,sizeof(Match)); -ans=0; -      for(intI=1; i<=n;i++) the     { -memset (CHW,0,sizeof(CHW));Wuyi         if(Ffind (i)) ans++;  the     } - } Wu  - intMain () About { $scanf"%d%d",&m,&n); -len=0; -memset (First,0,sizeof(first)); -      while(1) A     { +         intx, y; thescanf"%d%d",&x,&y); -         if(x==-1&&y==-1) Break; $ ins (x, y); the     } the solve (); theprintf"%d\n", ans); the     /*for (int i=m+1;i<=n;i++) if (Match[i]) -     { in printf ("%d%d\n", match[i],i); the     }*/ the     return 0;  About}
View Code

2016-11-04 08:40:05

"Network flow 24 questions" with pilots (pilot pairing scheme problem)

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.