Roller coaster
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 13476 Accepted Submission (s): 5901
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 Hungarian algorithm: This problem is the template of the Hungarian algorithm
#include <stdio.h> #include <string.h> #define MAX 1100int map[max][max];int vis[max];//record if this girl has a partner. int girl[max];//record girl with that boy now partner int K,n,m;int find (int x)//Judge The current boy can partner with that girl. If a partner returns 1 { //No partner returns 0 int i,j;for (i=1;i<=m; i++) {if (map[x][i]&&!vis[i])//If two people are in a affinity and the girl is not marked { //(This is marked by the girl and the first boys and has formed a partner) vis[i]=1;if (girl [i]==0| | Find (Girl[i])//If the girl does not have a partner or can change partners {Girl[i]=x;return 1;}}} return 0;} int main () {int j,i,t,x,y,sum;while (scanf ("%d", &k), k) {scanf ("%d%d", &n,&m); memset (map,0,sizeof (map)); memset (girl,0,sizeof (Girl)), while (k--) {scanf ("%d%d", &x,&y); map[x][y]=1;} Sum=0;for (i=1;i<=n;i++) {memset (vis,0,sizeof (VIS)); if (find (i)) sum++;} printf ("%d\n", sum);} return 0;}
Hdoj 2063 roller Coaster