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 ...
随机推荐
- js计时器的问题
不说话直接上代码了 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> & ...
- 虚拟机guest为windows7的环境下安装破解版simplify3d_3.0.2
情形: 1.主机(host):ubuntu 2.虚拟机里安装的操作系统版本(guest):windows 7专业版 3.simplify3d破解版版本:3.0.2(破解需要的工具均在下文的百度云地址里 ...
- zoj 1453 Surround the Trees(凸包求周长)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=453 Time Limit: 2 Seconds Memory ...
- Sbt的使用初步和用sbt插件生成eclipse工程
以前一直是用maven去管理java项目,现在开始写scala项目了但是在scala-ide中去编译scala项目和sbt的区别一直没弄清楚受到文章:http://my.oschina.net/yjw ...
- slogan
nasa to infinity and beyond Werner Vogels at amazon all things distributed Kelly Johnson at Lockheed ...
- 函数对象适配器之ptr_fun的使用示例
//============================================================================ // Name : CopyInts4.c ...
- mysql概要(十)触发器
1触发器可监视增删改,并触发增删改操作. 针对一些逻辑关联密切的操作,而不必手动多次操作. 2.要素: 3.语法: 补充:mysql可以设置结束符,不必是“:”来结束标志,可使用 3.1简单的例子: ...
- ccc
课本第291页第4题 #include<stdio.h> void main() { int n, m, i, k; int p_begin; ]; scanf("%d" ...
- nyoj 28 大数阶乘
题目链接:nyoj 28 就是个简单的高精度,只是一开始我打表超内存了,然后用了各种技巧硬是把内存缩到了题目要求以下(5w+kb),感觉挺爽的,代码如下: #include<cstdio> ...
- windows服务名称不是单个单词的如何启动?
比如要启动 Memcached Server: 命令行中输入命令要注意大小写,大小写要保持一致,正确的写法如下: net start "Memcached Server". ...