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 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.

 
Source
代码:
 #include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
int const maxn=;
int n,m;
bool mat[maxn][maxn];
bool vis[maxn];
int mac[maxn];
bool match(int x)
{
for(int i=;i<=n;i++)
{
if(mat[x][i]&&!vis[i]){
vis[i]=;
if(!mac[i]||match(mac[i])){
mac[i]=x;
return ;
}
}
}
return ;
}
int main(){
int a,b;
//freopen("test.in","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF){
memset(mat,,sizeof(mat));
memset(mac,,sizeof(mac));
for(int i=;i<=m;i++){
scanf("%d",&a);
while(a--){
scanf("%d",&b);
mat[i][b]=;
}
} int ans=;
for(int i=;i<=m;i++){
memset(vis,,sizeof(vis));
if(match(i))ans++;
}
printf("%d\n",ans);
}
return ;
}

hdu-----(1179)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. Ollivanders: Makers of Fine Wands since 382 BC.

    Ollivanders: Makers of Fine Wands since 382 BC.                                               Time L ...

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

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

  4. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  5. HDU 2236:无题II(二分搜索+二分匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=2236 题意:中文题意. 思路:先找出最大和最小值,然后二分差值,对于每一个差值从下界开始枚举判断能不能二分匹配. ...

  6. HDU 2063 过山车(二分匹配入门)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...

  7. 【HDU 2255】奔小康赚大钱 (最佳二分匹配KM算法)

    奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  8. hdu 1281棋盘游戏(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281   Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...

  9. HDU - 1045 Fire Net(二分匹配)

    Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...

随机推荐

  1. jquery动态样式操作

    获取与设置样式 获取class和设置class都可以使用attr()方法来完成.例如使用attr()方法来获取p元素的class,JQuery代码如下: 1 var p_class = $(" ...

  2. 应用部署到JBOSS上遇到的问题

    原来应用在WAS7.0下,移植到JBOSS eap5.1.2下后,遇到了一些问题,特此记录: 1.数据源配置 在was中,datasource中获取数据源名称时,直接写was中配置的数据源名称即可.而 ...

  3. 关于css3的自定义字体

    css3的@font-face属性打破了中文页面字体一成不变的格局,但今天本菜在用的时候并不那么爽.开始各种引用外部ttf文件失败.下了300M+的字体文件,苦逼的试了一下午.终于有一个ttf引用成功 ...

  4. poj1039Pipe(直线交点、叉积)

    链接 之前刷poj计划时刷过,不过也没什么印象了.打铁还是趁热,还没热起来就放弃了,前面算是做了无用功,有如胡乱的看解题报告一样. 题目应该是比较经典的集合入门题,黑书上有一部分核心讲解. 题目中的最 ...

  5. EAPOL 协议

    EAPOL 协议 一.基本概念 EAPOL 的全称为 Extensible Authentication Protocol Over LAN,即 EAP Over Lan,也即基于局域网的扩展认证协议 ...

  6. JQuery $()后面的括号里的内容什么时候加引号,什么时候不加

    一.如果是已经声明存在的变量或者对象,就不用加引号. 比如var name=document.getElementById("name"); $(name)或者$(this). 二 ...

  7. iOS 开发之照片框架详解(2)

    一. 概况 本文接着 iOS 开发之照片框架详解,侧重介绍在前文中简单介绍过的 PhotoKit 及其与 ALAssetLibrary 的差异,以及如何基于 PhotoKit 与 AlAssetLib ...

  8. PSR-0的规范。

  9. [C++]访问控制与继承(public,protect,private) 有时间再整理!!!

    http://www.cnblogs.com/chio/archive/2007/06/11/779408.html http://www.cnblogs.com/SelaSelah/archive/ ...

  10. Android布局_网格布局GirdLayout

    自Android4.0版本后新增的GirdLayout网格布局(API 14) <?xml version="1.0" encoding="utf-8"? ...