Roller coasterTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): 11520 Accepted Submission (s): 5072
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 Input
6 3 31 11 21 32 12 33 10
Sample Output
3
First two-part matching question ...
Purely a template.
Reference: http://blog.csdn.net/wellerzhao/article/details/7756956
Code Listing 1:
#include <stdio.h> #include <string.h> #define M 555int map[m][m];int mx[m], My[m];int vis[m];int N, m;int find (int s) {int i; for (i = 1; i<= m; i + +) {if (!vis[i]&&map[s][i]) {vis[i] = 1; if (my[i] = = 0| | Find (My[i])) {My[i] = s; Mx[s] = i; return 1; }}} return 0;} void F () {for (int i = 1; I <= n; i + +) printf ("%d. %d,,%d. %d\n ", I, mx[i], I, my[i]);} int main () {int k; while (scanf ("%d", &k), k) {int i; memset (map, 0, sizeof (map)); memset (MX, 0, sizeof (MX)); memset (my, 0, sizeof (my)); int A, B; scanf ("%d%d", &n, &m); for (i = 0; i < K; i + +) {scanf ("%d%d", &a, &b); MAP[A][B] = 1; } int ans = 0; for (i = 1; i<= n; i + +) {if (!mx[i]) {memset (Vis, 0, sizeof (VIS)); if (find (i)) ++ans; }} printf ("%d\n", ans); f (); } return 0;}
The following code is another form, but only the number of arrays ... Thought is still the same
Code
#include <stdio.h> #include <string.h> #define M 555int map[m][m];int mx[m], My[m];int vis[m];int N, m;int find (int s) {int i; for (i = 1; i<= m; i + +) {if (!vis[i]&&map[s][i]) {vis[i] = 1; if (my[i] = = 0| | Find (My[i])) {My[i] = s; Mx[s] = i; return 1; }}} return 0;} void F () {for (int i = 1; I <= n; i + +) printf ("%d. %d,,%d. %d\n ", I, mx[i], I, my[i]);} int main () {int k; while (scanf ("%d", &k), k) {int i; memset (map, 0, sizeof (map)); memset (MX, 0, sizeof (MX)); memset (my, 0, sizeof (my)); int A, B; scanf ("%d%d", &n, &m); for (i = 0; i < K; i + +) {scanf ("%d%d", &a, &b); MAP[A][B] = 1; } int ans = 0; for (i = 1; i<= n; i + +) {if (!mx[i]) {memset (Vis, 0, sizeof (VIS)); if (find (i)) ++ans; }} printf ("%d\n", ans); f (); } return 0;}
Hdoj 2063 roller coaster "binary matching Hungarian algorithm"