杭电-1179 魔法师与魔法棒(二分匹配模板)
来源:互联网 发布:java实现通用日志记录 编辑:程序博客网 时间:2024/05/23 19:20
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): 1503 Accepted Submission(s): 833
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.
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)
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 43 1 2 31 11 10
Sample Output
2Wand 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.HintHint
Source
Gardon-DYGG Contest 1
#include<stdio.h> #include<string.h> int map[1110][1110]; int pei[1110]; int vis[1110]; int n,m; int find(int x) { int i; for(i=1;i<=m;i++) { if(map[x][i]==1&&!vis[i]) { vis[i]=1; if(!pei[i]||find(pei[i])) { pei[i]=x; return 1; } } } return 0; } int main() { while(scanf("%d%d",&n,&m)!=EOF) { int i,j,k; memset(map,0,sizeof(map)); memset(pei,0,sizeof(pei)); for(i=1;i<=m;i++) { scanf("%d",&k); while(k--) { scanf("%d",&j); map[i][j]=1; } } int ans=0; for(i=1;i<=n;++i) { memset(vis,0,sizeof(vis)); if(find(i)) ans++; } printf("%d\n",ans); } return 0; }
0 0
- 杭电-1179 魔法师与魔法棒(二分匹配模板)
- 二分匹配(模板)
- 二分匹配模板()
- 杭电2458 Kindergarten(二分图最大匹配)
- 杭电2063二分图匹配(匈牙利算法)
- 杭电 hdu 2063 (最基础的 二分匹配)
- 杭电 hdu 1083 Courses (二分匹配 )
- 杭电 hdu 1150 Machine Schedule (二分匹配)
- 杭电 HDU ACM 1150 Machine Schedule(二分匹配)
- 杭电-1498 50 years, 50 colors(二分匹配)
- 杭电ACM2063(二分图匹配)
- 杭电ACM1083(二分图匹配)
- 杭电1068二分图匹配
- 杭电-4545魔法串(LCS)
- 二分匹配(匈牙利算法)【模板】
- poj 1469 COURSES(二分匹配模板)
- 二分匹配(匈牙利算法)模板
- 匈牙利算法(二分图匹配)模板
- 小括号'()'运算符重载、逻辑与'&&'、逻辑或'||'运算符重载说明(需要了解)
- Maven搜索依赖库的顺序
- python unicode字节串转成中文问题
- Android动画总结系列(4)——属性动画集成
- UVA 11090 Going in Cycle!! SPFA判断负圈
- 杭电-1179 魔法师与魔法棒(二分匹配模板)
- ZZULIOJ 1918 G
- 宝藏
- zzulioj-1918-G【匈牙利算法】【二分匹配】
- Mysql 5.7 主从复制的多线程复制配置方式以及读写分离中间件 MaxScale
- c++ 关于map的遍历 删除
- TeeChart的安装 delphi7
- 多重背包详解
- Merge k Sorted Lists解题报告