Hdoj 2063 Roller Coaster "Bilateral matching Hungarian algorithm"

Source: Internet
Author: User

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 go to the amusement park to play with everybody today. Finally, you can sit on your dream roller coaster. However, there are only two seats in each row of the roller coaster, and there is an unwritten rule. Is that every girl must find all the boys to do partner and her sit.

But every girl has her own ideas, give me a sample. Rabbit only Willing and xhd or pqk do partner,grass just willing and linle or ll do partner. Princesssnow is willing to do partner with the water prodigal or pseudo queer.

Consideration of the financial implications. Boss Liu decided to just let people find partner to ride the roller coaster. Other people, hey, just stand here and watch. Smart Acmer, can you help calculate the maximum number of combinations that can be on a roller coaster?
The first line of input data is three integers k, M, N, representing the number of possible combinations, and the number of females. The number of boys. 0<k<=1000
1<=n and m<=500. The next K-line, each line has two numbers. The female AI is willing to do partner with the boy BJ respectively. 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

The first two-part matching question.

Purely a template.

References: 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;}


Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Hdoj 2063 Roller Coaster "Bilateral matching Hungarian algorithm"

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.