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): 520    Accepted Submission(s): 294

Problem Description
         In 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 loud 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 would blink.Those sivery eyes were a bit creepy.
'Your father, on the other hand, favoured a mahogany wand.Eleven inches.Pliable.A little more power and excellent for transfiguration.Well ,I say your father favoured 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 many customer that day.Though Ollivader knew every wand's favourite,he could not choose as many 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 sell wands as many as possible.

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

 
Input
There 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)
 
Output
Only one integer,shows how many wands Ollivander can sell.
 
Sample Input
3 4
3 1 2 3
1 1
1 1
0
 
Sample Output
2

Hint

Hint

Wand 1 fits everyone, Wand 2,3 only fit the first wizard,and Wand 4 does not fit anyone.So Ollivanders can sell two wands:
sell Wand 1 to Wizard 2 and Wand 2 to Wizard 1,or sell Wand 1 to Wizard 3 and Wand 3 to Wizard 1 ,or some other cases. But
he cannot sell 3 wands because no 3 wands just fit 3 wizards.

 
 
 
 
题意:
 
     其中有用的信息只有上文中深红色的字体。
 
    就是有N个魔法师,给你M根魔杖,然后告诉你每根魔杖可以匹配的魔法师。然后叫你进行求解最大匹配个数。很裸的最大匹配问题。而且深深的感受到出题的人真是无聊到了极致,难以理解他是为了考算法还是考英语阅读理解。。。。真心的鄙视。最后还要最意输入时候的格式。
 
 
#include <stdio.h>
#include <string.h>
#define CL(x,v);memset(x,v,sizeof(x)); const int maxn = 100 + 10;
int n,m,link[maxn];
bool used[maxn],graph[maxn][maxn]; int Find(int u)
{
for(int v = 1;v <= n;v++)
if(!used[v]&&graph[u][v])
{
used[v] = 1;
if(link[v] == -1||Find(link[v]))
{
link[v] = u;
return 1;
}
}
return 0;
}
int KM()
{
int res = 0;
CL(link,-1);
for(int u = 1;u <= m;u++)
{
CL(used,0);
res += Find(u);
}
return res;
}
int main()
{
int i,j,k,vex;
while(~scanf("%d%d",&n,&m))
{
CL(graph,0);
for(i = 1;i <= m;i++)
{
scanf("%d",&k);
for(j = 0;j < k;j++)
{
scanf("%d",&vex);
graph[i][vex] = 1;
}
}
printf("%d\n",KM());
}
return 0;
}

 

Ollivanders: Makers of Fine Wands since 382 BC.的更多相关文章

  1. hdu-----(1179)Ollivanders: Makers of Fine Wands since 382 BC.(二分匹配)

    Ollivanders: Makers of Fine Wands since 382 BC. Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  2. HDU——1179 Ollivanders: Makers of Fine Wands since 382 BC.

    Ollivanders: Makers of Fine Wands since 382 BC. Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  3. hdu-1179 Ollivanders: Makers of Fine Wands since 382 BC.---二分图匹配模板

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1179 题目大意: 有n个人要去买魔杖,有m根魔杖(和哈利波特去买魔杖的时候一样,是由魔杖选人).接下 ...

  4. hdu-1179-二分图最大匹配

    Ollivanders: Makers of Fine Wands since 382 BC. Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  5. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  6. 「日常温习」Hungary算法解决二分图相关问题

    前言 二分图的重点在于建模.以下的题目大家可以清晰的看出来这一点.代码相似度很高,但是思路基本上是各不相同. 题目 HDU 1179 Ollivanders: Makers of Fine Wands ...

  7. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  8. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  9. 【HDOJ图论题集】【转】

    =============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...

随机推荐

  1. java中获得jar包执行路径的方法

    当我们由于某种需要需要的得到jar的路径是可以用下面的方式来获得: basePath = new Solution().getClass().getProtectionDomain().getCode ...

  2. ORMBase对象/关系型数据库映射在MVC中的应用

    ORM这个字眼在我们操作数据库的时候,是我们使用频率最高的.它到底是个什么东西呢,我们先来看看一些对它的含义解释. 对象/关系数据库映射(object/relational mapping(ORM)) ...

  3. POJ 1275 Cashier Employment(差分约束)

    http://poj.org/problem?id=1275 题意 : 一家24小时营业的超市,要雇出纳员,需要求出超市每天不同时段需要的出纳员数,午夜只需一小批,下午需要多些,希望雇最少的人,给出每 ...

  4. 如何使用MIME类型

    今天在使用System.Net.WebClient做一个下载的时候,很郁闷,已经发不好的文件视频,却怎么也下载不了. 究其原因有两个, System.Net.WebClient对象的DownloadF ...

  5. poj3373Changing Digits(dp)

    链接 dfs倒着搜 返回的路径不能满足相同的数最多 借鉴了下别人的代码.. 先dp出来 再倒着标记一下 然后正回来一定可以满足了 dp保存的是最小的不相同数 #include <iostream ...

  6. [swustoj 191] 迷宫逃离

    迷宫逃离(0191) 描述 江鸟突然想到了一个迷宫逃离的游戏,话说有三个人被困于一个n*m的迷宫里,他们三人都可以向上.向下.向左.向右四个方向进行走动,当然他们所在的初始位置没有障碍物,同时只能走到 ...

  7. sharepoint 2010 隐藏左边菜单left menu样式脚本

    转:http://www.cfanz.cn/?c=article&a=read&id=60536 在v4.master中,<head></head>标签中,加入 ...

  8. tomcat7 使用log4j进行日志记录

    将 tomcat-juli.jar 文件放置到 $CATALINA_BASE/bin 目录(实际上,该目录下已经有了) 从 log4j 网站下载 jar 包,并放置于 $CATALINA_BASE/l ...

  9. JDK源码重新编译——支持eclipse调试JDK源码--转载

    最近在研究jdk源码,发现debug时无法查看源码里的变量值. 因为sun提供的jdk并不能查看运行中的局部变量,需要重新编译一下rt.jar. 下面这六步是编译jdk的具体步骤: Step 1:   ...

  10. Esper系列(九)NamedWindow语法create、Insert、select

    功能:用于存储一种或多种类型的事件的集合,并能对所存储的事件进行增删改查操作. CreateNameWindow 根据已有的数据源构造 格式: 1  [context context_name]  2 ...