HDU ----- (1179) ollivanders: makers of fine wands since 382 BC. (Binary match)

Source: Internet
Author: User
Ollivanders: makers of fine wands since 382 BC.

Time Limit: 2000/1000 MS (Java/others) memory limit: 131072/65536 K (Java/Others)
Total submission (s): 935 accepted submission (s): 523


Problem descriptionin Diagon Alley, there is only one wand-seller, peeling gold letters over the door read ollivanders: makers of fine wands since 382 BC. A single wand lay on a faded purple cushion in the dusty window.
A tinkling bell rang somewhere in the depths of the shop as they stepped inside. it was a tiny place, empty execpt for a single spindly chair which Hagrid sat on to wait. harry felt strangely as though he had entered a very strict library; he swallowd a log of new questions which had just occurred to him and looked instead at the thousands of narrow boxes piled neatly right up to the ceiling. for some reason, the back of his neck prickled. the very dust and silence in here seemed to tingle with some secret magic.
'Good afternoon, 'said a soft voice. Harry jumped. Hagrid must have jumped, too, because there was a random crunching noise and he got quickly off the spindly chair.
An old man was standing before them, his wide pale eyes shining like moons through the gloom of the shop.
'Hello, 'said Harry awkwardly.
'Ah yes, 'said the man. 'Yes, yes. I thought I 'd be seeing you soon, Harry Potter. 'It wasn' t a question. you have your mother's eyes. it seems only yesterday she was in here herself, buying her first wand. ten and a quarter inches long, swishy, made of willow. nice wand for charm work.'
Mor Ollivander moved closer to Harry. Harry wished he wowould blink. Those sivery eyes were a bit creepy.
'Your father, on the other hand, favored a mahogany wand. eleven inches. pliable. A little more power and excellent for transfiguration. well, I say your father favored it-it's really the wand that choosed the wizard, Of cource.'

Yes, some wands fit some wizards, as we all know. but what Harry doesn' t know is Ollivander have met a big trouble. that's more than twenty years ago, when Harry's father James Potter was still a student in Hogwarts. he went Diagon Alley to buy new books, passing by Ollivander's shop. ollivander was crazy for a problem: he was too busy to choose most suitable wand for every wizard. even more, there are too every customer that day. though ollivader knew every wand's favorite, he cocould not choose as your Wizards as possible to get the wands. so James Potter, a very clever man, gave him a magic disk with your program, to help him parse wands as stored as possible.

Please notice: One wand can only be sold to one wizard, and one wizard can only buy one wand, too.

 

Inputthere are several cases. for each case, there is two integers n and m in the first line, which mean there is n wizards and M wands (0 <n <= m <= 100 ).
Then M lines contain the choices of each wand. the first integer in I + 1th line is Ki, and after these there are ki integers Bi, J which are the wizards who fit that wand. (0 <= Ki <= N, 1 <= Bi, j <= N)

 

Outputonly one integer, shows how does wands Ollivander can handle.

 

Sample input3 43 1 2 31 11 10

 

Sample output2 HintHintwand 1 fits everyone, wand 2, 3 only fit the First Wizard, And wand 4 does not fit anyone. so ollivanders can have two wands: Too wand 1 to Wizard 2 and wand 2 to Wizard 1, or too wand 1 to Wizard 3 and wand 3 to Wizard 1, or some other cases. but he cannot found 3 wands because no 3 wands just fit 3 wizards.

 

Source gardon-dygg contest 1 code:
 1 #include<cstring> 2 #include<cstdio> 3 #include<cstdlib> 4 using namespace std; 5 int const maxn=102; 6 int n,m; 7 bool mat[maxn][maxn]; 8 bool vis[maxn]; 9 int mac[maxn];10 bool match(int x)11 {12     for(int i=1;i<=n;i++)13     {14         if(mat[x][i]&&!vis[i]){15             vis[i]=1;16             if(!mac[i]||match(mac[i])){17                 mac[i]=x;18                 return 1;19             }20         }21     }22     return 0;23 }24 int main(){25     int a,b;26     //freopen("test.in","r",stdin);27     while(scanf("%d%d",&n,&m)!=EOF){28        memset(mat,0,sizeof(mat));29        memset(mac,0,sizeof(mac));30        for(int i=1;i<=m;i++){31          scanf("%d",&a);32         while(a--){33          scanf("%d",&b);34          mat[i][b]=1;35         }36     }37 38     int ans=0;39     for(int i=1;i<=m;i++){40       memset(vis,0,sizeof(vis));41       if(match(i))ans++;42     }43     printf("%d\n",ans);44  }45   return 0;46 }
View code

 

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.