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): 14056 A ccepted Submission (s): 6196 problem DESCRIPTIONRPG Girls today 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 to ten, sample OUTPUT3 |
#include <stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>#defineN 1010#defineINF 0x3f3f3f3fintG[n][n], used[n], vis[n], N;BOOLFind (intu) { inti; for(i =1; I <= N; i++) { if(!vis[i] &&G[u][i]) {//Vis[i] means I haven't been picked by another girl.Vis[i] =1; if(!used[i] | |Find (Used[i])) {//if the girl Used[i] did not choose boys I partner or girls Used[i] chose male I, she gave up boys I and found their own companionUsed[i] = u;//let the boys I and girl U partner return true; } } } return false;}//This function determines if a girl loves to find a companion .intMain () {intK, M, I, A, b, ans; while(SCANF ("%d", &k), K) {ans=0; memset (G,0,sizeof(G)); scanf ("%d%d", &m, &N); while(k--) {scanf ("%d%d", &a, &b); G[A][B]=1;//g[a][b] says girl A is willing to partner with Boy B}//Used[i] means I boys and used[i] Girl partnersmemset (Used,0,sizeof(used)); for(i =1; I <= m; i++) {memset (Vis,0,sizeof(VIS)); if(Find (i)) ans++; } printf ("%d\n", ans); } return 0;}
HDU 2063 roller coaster (Hungarian algorithm template)