Simple question hdu2063
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2063
Roller coaster
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 13500 Accepted Submission (s): 5913
Problem DESCRIPTIONRPG girls today and we go to the amusement park to play, finally can sit on the dream of the roller coaster. However, the roller coaster in each row only two seats, and there is an unwritten rule, is that every girl must find all the boys do partner and her sitting. However, each girl has their own ideas, for example, rabbit only willing and xhd or pqk do Partner,grass only willing and linle or ll do partner,princesssnow willing and water prodigal or pseudo-queer do partner. Considering the financial problems, boss Liu decided to only find partner people to ride the roller coaster, other people, hey, just stand down and watch it. Smart Acmer, can you help calculate the maximum number of pairs can be on the roller coaster?
The first line of input data is three integers k, M, N, each representing the number of possible combinations, the number of girls, and the number of males. 0<k<=1000
1<=n and m<=500. The next K-line, each line has two numbers, respectively, the female AI is willing to and boys BJ do partner. Last 0 end input.
Output for each set of data, outputs an integer that represents the maximum number of combinations that can be seated on a roller coaster.
Sample INPUT6 3 31 11 21 32 12 33 10
Sample OUTPUT3
Authorprincesssnow
SOURCERPG Special Practice game title to the main idea: is to match as many pairs as possible, let them play to the roller coaster. See the code.
1#include <iostream>2#include <cstdio>3#include <cstring>4 5 using namespacestd;6 7 intmap[510][510],vis[510],n,m;8 intok[510];//OK, that's what the man was occupying.9 Ten BOOLFind (intx) One { A for(intI=1; i<=n; i++)//Scan every boy - { - if(map[x][i]==1&&!vis[i])//The vis here is to avoid a dead loop. the { -vis[i]=1; - if(!ok[i])//have not been occupied - { +ok[i]=x; - return true; + } A Else at { - if(Find (ok[i]) = =true)//have been occupied, to help them find a look whether to find the - { -Ok[i]=x;//If you can get it, give it to X. - return true; - } in - } to } + } - return false; the } * $ intMain ()Panax Notoginseng { - intk,ans,a,b; the while(~SCANF ("%d",&k)) + { A if(k==0) the Break; +scanf"%d%d",&m,&n); -ans=0; $memset (Map,0,sizeof(MAP)); $Memset (OK,0,sizeof(OK)); - for(intI=1; i<=k; i++) - { thescanf"%d%d",&a,&b); -map[a][b]=1;Wuyi } the for(intI=1; i<=m; i++) - { Wumemset (Vis,0,sizeof(Vis)); - if(Find (i) = =true) About { $ans++; - } - } -printf ("%d\n", ans); A } + return 0; the}
HDU 2063 roller coaster binary matching (Hungarian algorithm)