HDU 1669 Jamie's contact groups

Source: Internet
Author: User
Jamie's contact groups

Time Limit: 15000/7000 MS (Java/others) memory limit: 65535/65535 K (Java/Others)
Total submission (s): 225 accepted submission (s): 63

Problem descriptionjamie
Is a very popular girl and has quite a lot of friends, so she always
Keeps a very long contact list in her cell phone. The contact list has
Become so long that it often takes a long time for her to browse through
The whole list to find a friend's number. As Jamie's best friend and
Programming genius, you suggest that she group the contact list and
Minimize the size of the largest group, so that it will be easier
Her To search for a friend's number among the groups. Jamie takes your
Advice and gives you her entire contact list containing her friends'
Names, the number of groups she wishes to have and what groups every
Friend cocould belong to. Your task is to write a program that takes
List and organizes it into groups such that each friend appears in only
One of those groups and the size of the largest group is minimized. inputthere
Will be at most 20 test cases. Specify case starts with a line containing
Two integers n and M. where N is the length of the contact list and M is
The number of groups. n lines then follow. Each line contains
Friend's name and the groups the friend cocould belong to. You can assume n
Is no more than 1000 and M is no more than 500. The names will contain
Alphabet letters only and will be no longer than 15 characters. No two
Friends have the same name. The group label is an integer between 0 and m
-1. After the last test case, there is a single line '0 0' that
Terminates the input. outputfor each test case, output a line containing a single integer, the size of the largest contact group. sample input3 2 John 0 1 rose 1 Mary 15 4acm 1 2 3 ICPC 0 1 Asian 0 2 3 Regional 1 2 Shanghai 0 2
0 0 sample output2
2 source 2004 Asia Regional Shanghai recommendxhd is easy to understand. I will not go into details here. I still click graph theory after the divisional competition. I hope I can really give it to the primary node. The idea of this topic is the multi-matching of the binary + bipartite graph. Next I will put my scum Code Get it up: View code

# Include <algorithm> # Include <Iostream> # Include <Cstdlib> # Include <Cstring> # Include <Cstdio> Using   Namespace  STD;  Const   Int Maxn = 1010  ;  Const   Int Maxm = 510  ;  Int  Bmap [maxn] [maxm], CY [maxm] [maxn], bmask [maxm], vcy [maxm], n, m, limit;  Char S [ 2000  ];  Bool Findpath ( Int  U ){  For (Int I = 0 ; I <m; I ++ ){  If (Bmap [u] [I] &! Bmask [I]) {bmask [I] = 1  ;  If (Vcy [I] < Limit) {CY [I] [vcy [I] ++] = U;  Return   True  ;} For ( Int J = 0 ; J <vcy [I]; j ++ ){  If  (Findpath (CY [I] [J]) {CY [I] [J] = U;  Return   True  ;}}}}  Return   False  ;}  Bool Mulmatch () {memset (vcy,  0 , (M + 5 )* Sizeof ( Int  ));  For ( Int I = 0 ; I <n; I ++ ) {Memset (bmask,  0 , Sizeof  (Bmask ));  If (! Findpath (I ))Return   False  ;}  Return   True  ;}  Int  Main (){  While (Scanf ( "  % D  " , & N, & M), N + M) {getchar (); memset (bmap,  0 , Sizeof (Bmap); memset (CY,  0 , Sizeof  (CY); memset (S,  0 , Sizeof  (S ));  For ( Int I = 0 ; I <n; I ++ ) {Gets (s );  Int Len = Strlen (s );  Int Ret =0  ;  Int  T;  For (T = 0 ; T <Len; t ++ ){  If (S [T]> = '  A  ' & S [T] <= '  Z  ' ) | (S [T]> = ' A  ' & S [T] <= '  Z  ' )) Continue  ;  Else   Break  ;} T ++ ;  For (; T <Len; t ++ ){  If (S [T]> ='  0  ' & S [T] <= '  9  '  ) {RET = RET * 10 + S [T]- '  0  '  ;  If (T + 1 = Len) bmap [I] [RET] = 1  ;}  Else   If (S [T] = '   '  ) {Bmap [I] [RET] = 1  ; RET = 0  ;} Memset (S,  0 , Sizeof  (S ));} Int L = 1 , R = N + 1 , ANS = 0  ;  While (L < R) {limit = (L + r)> 1  ;  If  (Mulmatch () ans = Limit, r = Limit;  Else L = Limit + 1 ;} Printf (  "  % D \ n  "  , ANS );}  Return   0  ;} 

We are about to leave tomorrow night. It is said that the legendary death division, so the mentality is also very good, basically to play, because know their own level. Thank you! You are welcome to repost, ask, and leave a message.

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.