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 ...
随机推荐
- Nodejs发送Post请求时出现socket hang up错误的解决办法
参考nodejs官网发送http post请求的方法,实现了一个模拟post提交的功能.实际使用时报socket hang up错误. 后来发现是请求头设置的问题,发送选项中需要加上headers字段 ...
- JS cookie的使用
js设置cookie有很多种方法. 第一种:(这个是w3c官网的代码) <script> //设置cookie function setCookie(cname, cvalue, exda ...
- 统计fastq文件中读段的数量
mycount=`cat SRR108114_new_1.fastq | wc -l` echo 'Number of clean reads, SRR108114_new_1.fastq: '$(( ...
- IO设计模式:Reactor和Proactor对比
IO设计模式:Reactor和Proactor对比 平时接触的开源产品如Redis.ACE,事件模型都使用的Reactor模式:而同样做事件处理的Proactor,由于操作系统的原因,相关的开源产品也 ...
- html中出现的script失效
如果在Controller中出现script代码类似 $hello_str='Hello God<script>alert(3);</script>'; 那么我不希望在传给vi ...
- Nginx基础知识之——配置文件信息(检查配置文件是否正确)
一.检查配置文件是否正确: /usr/local/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf 检查结果: nginx: [emerg] ngin ...
- Python学习(21)python操作mysql数据库_操作
目录 数据库连接 创建数据库表 数据库插入操作 数据库查询操作 数据库更新操作 删除操作 执行事务 错误处理 数据库连接 连接数据库前,请先确认以下事项: 您已经创建了数据库 TEST. 在TEST数 ...
- linux之稀疏文件
1. Sparse 文件是并不占用磁盘存储空间. 2. rm 某文件后, 文件占用的磁盘空间并不是立即释放, 而是其句柄没有被任意一个进程引用时才回收. 3. ls 的结果是 apparent siz ...
- (五)stm32工程代码HardFault异常查错调试方法
一.导致异常的原因很多,例如:直接使用未分配空间的指针.栈溢出等一场非法操作便会使程序进入HardFault异常状态.下面介绍怎么找出程序中的异常. 接下来在keil_MDK工程中,编译代码,并deb ...
- (四)C语言柔性数组、指针赋值
一.柔性数组 今天看了公司的代码,发现一个很奇怪的问题,后来自己写了类似代码,我先把代码贴出来吧. #include<stdio.h> #include<string.h> # ...