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. UVA 10453 十七 Make Palindrome

    Make Palindrome Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit St ...

  2. 关于directX最近的学习方案

    目标:弄清楚如何渲染一个地形,以及人物坐标以及摄像机方向,弄清四大矩阵原理 实践: 1.再次学习矩阵相关知识 2.实现红龙本书的地形 3.搜寻这方面资料书籍

  3. JavaWeb(一)

    Web应用程序开发是目前软件开发领域的三大方向之一. 静态网页与动态网页 静态网页 表现形式:网页的内容是固定的,不会更新: 使用的技术:HTML,CSS 动态网页 表现形式:网页中的内容通过程序动态 ...

  4. MS16-016 提权EXP

    测试环境 win7 32 位未打任何补丁 1.使用net user 指令 测试得到结果没有权限新建用户 2.查看系统用户 3.复制EXP到win7 下  使用命令打开 添加新用户再查看用户列表

  5. POJ 3461 Oulipo(乌力波)

    POJ 3461 Oulipo(乌力波) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] The French autho ...

  6. idea编辑器HttpServlet httpServlet = ServletActionContext.getServletContext().getRealPath();方法无法使用

    HttpServlet httpServlet = ServletActionContext.getServletContext().getRealPath(); 前几天在使用idea的时候发现这个方 ...

  7. Android简单登陆页面

    布局: 线性布局+相对布局 日志打印: 利用LogCat和System.out.println打印观察. Onclick事件是采用过的第四种: 在配置文件中给Button添加点击时间 涉及知识: 通过 ...

  8. OCR识别-python版(一)

    需求:识别图片中的文字信息环境:windows系统 开发语言:python 使用工具类:1.pyocr 2.PIL 3.tesseract-ocr 步骤: 1.pyocr 网络通直接使用命令:pip ...

  9. web设计经验<一> 提升移动设备响应式设计的8个建议

    今天看到一些关于web设计的一些建议和设计经验,拿出来分享分享. 第一篇: 提升移动设备响应式设计的8个建议 一.直观性和易用性 在使用移动设备时,对于杂乱.复杂或者不直观的设计造成的混乱不佳的用户体 ...

  10. oracle 索引失效原因及解决方法

    oracle 索引失效原因及解决方法 2010年11月26日 星期五 17:10 一.以下的方法会引起索引失效 ‍1,<>2,单独的>,<,(有时会用到,有时不会)3,like ...