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 Limit: 131072/65536 K (Java/Others)
Total Submission(s): 935 Accepted Submission(s): 523
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.
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)
3 1 2 3
1 1
1 1
0
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.
#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.(二分匹配)的更多相关文章
- 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 ...
- Ollivanders: Makers of Fine Wands since 382 BC.
Ollivanders: Makers of Fine Wands since 382 BC. Time L ...
- hdu-1179 Ollivanders: Makers of Fine Wands since 382 BC.---二分图匹配模板
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1179 题目大意: 有n个人要去买魔杖,有m根魔杖(和哈利波特去买魔杖的时候一样,是由魔杖选人).接下 ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- HDU 2236:无题II(二分搜索+二分匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=2236 题意:中文题意. 思路:先找出最大和最小值,然后二分差值,对于每一个差值从下界开始枚举判断能不能二分匹配. ...
- HDU 2063 过山车(二分匹配入门)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...
- 【HDU 2255】奔小康赚大钱 (最佳二分匹配KM算法)
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- hdu 1281棋盘游戏(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...
- HDU - 1045 Fire Net(二分匹配)
Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...
随机推荐
- Download file using libcurl in C/C++
http://stackoverflow.com/questions/1636333/download-file-using-libcurl-in-c-c #include <stdio.h&g ...
- ASP.NET四则运算--策略模式
在ASP.NET中实现四则运算,同样使用了类的封装,以及策略模式.只不过是把封装的类.前台代码以及后台的代码分离开来,但同样是要达到功能的实现. Calculator.cs using System; ...
- java传递和返回对象
java传递的只是一个引用,一定要注意准确认识在对象传递和赋值时所发生的一切. 事实上,java中的每个对象(除了基本数据类型以外)的标识符都属于指针的一种,但是其使用受到了严格的限制和防范,不仅在编 ...
- [SAP ABAP开发技术总结]业务对象和BAPI
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- python_way day13 sqlalchemy
sqlalchemy 一对多 多对多 1.一对多 一.#创建表结构 class Host(Base): #所有的子类都继承这个基类 #创建表结构 __tablename__ = 'hosts' id ...
- SQL查询语句 group by后, 字符串合并
合并列值 --******************************************************************************************* 表 ...
- NYOJ 93 汉诺塔(三)
汉诺塔(三) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 在印度,有这么一个古老的传说:在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝石针.印度 ...
- hibernate对象关系实现(三)多对多实现
单向n-n:(catogory-item)一个类别对应多个条目,一个条目对应多个类别 a.以类别类中有条目的集合的引用为例: b.数据库中的体现:建立一个新表,以类别和条目的主键关联的外键做新表的联合 ...
- Doragon Kuesuto 1.6
/* * <<D Q>> * * Author xkfx<wyzxk_fx@163.com> * * 游戏规则:利用适当的决策,在13回合内击杀恶龙取得胜利. * ...
- js的事件处理程序
js事件处理程序一般有三种: 1.HTML事件处理程序 <body> <input type="button" value="点击" oncl ...