博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU Problem 1179 Ollivanders: Makers of Fine Wands since 382 BC.【二分图匹配】
阅读量:6870 次
发布时间:2019-06-26

本文共 4492 字,大约阅读时间需要 14 分钟。

 

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)

Total Submission(s): 1515    Accepted Submission(s): 843

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
 

 

Recommend
JGShining   |   We have carefully selected several similar problems for you:            
 
#include 
#include
#include
#include
#include
#include
#define space " "using namespace std;//typedef __int64 Int;//typedef long long LL;const int INF = 0x3f3f3f3f;const int MAXN = 100 + 10;const double Pi = acos(-1.0);const double ESP = 1e-5;vector
G[MAXN];int match[MAXN];bool used[MAXN];void init(int x) { for (int i = 0; i <= x; i++) { G[i].clear(); match[i] = -1; }}bool Dfs(int x) { for (int i = 0; i < G[x].size(); i++) { int t = G[x][i]; if (used[t]) continue; used[t] = true; if (match[t] == -1 || Dfs(match[t])) { match[t] = x; return true; } } return false;}int main() { int n, m, a, k; while (scanf("%d%d", &n, &m) != EOF) { init(m); int ans = 0; for (int i = 1; i <= m; i++) { scanf("%d", &k); for (int j = 0; j < k; j++) { scanf("%d", &a); if (a) G[i].push_back(a); } } for (int i = 1; i <= m; i++) { memset(used, false, sizeof(used)); if (Dfs(i)) ans++; } printf("%d\n", ans); } return 0;}

 

 

 

 

转载于:https://www.cnblogs.com/cniwoq/p/6770821.html

你可能感兴趣的文章
物联网数据卡系统源码——通信模块整体概述
查看>>
《学习OpenCV3》目录和全书划分
查看>>
翻转字符串
查看>>
生活娱乐 24岁姑娘端22碗米粉面不改色
查看>>
2-05. 求集合数据的均方差(15) (数学啊 ZJU_PAT)
查看>>
城市公交网建设问题
查看>>
Android图片加载框架Picasso最全使用教程5
查看>>
静态与伪静态
查看>>
SAML
查看>>
安装配置PhoneGap开发环境(一)
查看>>
设计模式学习笔记--备忘录(Mamento)模式
查看>>
OGG目的端的checkpoint table被drop的修复方法
查看>>
android 通过bitmapfactory得到图片真实像素的方法,以及没有得到真实像素的原因
查看>>
SVN 常见命令
查看>>
poj 2299 Ultra-QuickSort
查看>>
mysql写注释的几种方法
查看>>
MFC窗口去边框、置顶、全屏、激活
查看>>
SSH-CLIENT : gSTM
查看>>
HTML5 Audio/Video 标签,属性,方法,事件汇总 (转)
查看>>
HDU 3572 Task Schedule(ISAP模板&amp;&amp;最大流问题)
查看>>