HDU 1498 years, colors (binary matching _ Hungarian algorithm)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1498

Years, colors

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1918 Accepted Submission (s): 1058


Problem Descriptionon Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nice, Isn ' t it? To celebrate this meaningful day, the ACM team of HDU hold some fuuny games. Especially, there'll be a game named "Crashing Color Balloons".

There'll is a n*n matrix board on the ground, and each grid would have a color balloon in it. and the color of the ballon is in the range of [1, 50]. After the referee shouts ' go! ', you can begin to crash the balloons. Every time you can only choose one kind of balloon to crash, we define that the both balloons with the same color belong to The same kind. What's more, each time you can is choose a single row or column of balloon, and crash the balloons that with the color Y Ou had chosen. Of course, a lot of students is waiting to play this game, so we just give every student K times to crash the balloons.

Here comes the Problem:which kind of balloon are impossible to being all crashed by a student in K times.

Inputthere'll be multiple input cases. Each test case begins with the integers n, K. N is the number of rows and columns of the balloons (1 <= n <=), a nd k is the Times, ginving to each student (0 < K <= N). Follow a matrix A of n*n, where Aij denote the color of the ballon in the I row, j column. Input ends with n = k = 0.

Outputfor each test case, print in ascending order all the colors of which is impossible to being crashed by a student in K Times. If There is no choice, print "-1".

Sample INPUT1 112 11 11 22 11 22 25 41 2 3 4 52 3 4 5 13 4 5 1 24 5 1 2 35 1 2 3 43 350 50 5050 50 5050 50 500 0

Sample Output-1121 2 3 4 5-1

Author8600

Source "2006 Campus cultural activity Month" of "School Anniversary Cup" College students Program Design Competition and Hangzhou University of Engineering fourth session of college students program design contest the main idea: brush balloons, balloons have many kinds of colors. Each time the balloon can brush a whole row or a whole column, brush m times, the final output of the balloon number. (Each different number represents a different color of the balloon). Special Note: The color number range of balloons is between 1~50. See Code (Code explanation)
1#include <iostream>2#include <cstdio>3#include <cstring>4 5 using namespacestd;6 7 intn,m;8 intvis[ the],map[ the][ the],ok[ the],cc[ -];9 Ten BOOLFind (intXintNow ) One { A      for(intI=1; i<=n; i++) -     { -         if(!vis[i]&&map[x][i]==Now ) the         { -vis[i]=1; -             if(!Ok[i]) -             { +ok[i]=x; -                 return true; +             } A             Else at             { -                 if(Find (ok[i],now)) -                 { -ok[i]=x; -                     return true; -                 } in             } -         } to     } +     return false; - } the  * intMain () $ {Panax Notoginseng     intflag,ans,s[ the]; -      while(~SCANF ("%d%d",&n,&m)) the     { +flag=0; AMemset (CC,0,sizeof(cc)); thememset (Map,0,sizeof(MAP)); +         if(n==0&&m==0) -              Break; $          for(intI=1; i<=n; i++) $         { -              for(intj=1; j<=n; J + +) -             { thescanf"%d",&map[i][j]); -cc[map[i][j]]=1;//record This color has appearedWuyi             } the         } -Memset (OK,0,sizeof(OK)); Wu         intk=0; -          for(intI=1; i<= -; i++) About         { $Memset (OK,0,sizeof(OK)); -ans=0; -             if(cc[i]==1)//determine if the color has occurred, added here do not mark the final output is not painted color numbers, will output some messy things -             { A                  for(intj=1; j<=n; J + +) +{ thememset (Vis,0,sizeof(Vis)); -                     if(Find (j,i)) $ans++; the                 } the                 if(ans>m)//if the maximum number of matches is greater than M, the brush is endless. the                 { thes[++k]=i; -flag=1; in                 } the             } the         } About         if(flag==0) theprintf ("-1\n"); the         Else the         { +              for(intI=1; i<k; i++)//Control output Format -             { theprintf ("%d", S[i]);Bayi             } theprintf ("%d\n", S[k]); the         } -     } -     return 0; the}

HDU 1498 years, colors (binary 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.