博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU——1179 Ollivanders: Makers of Fine Wands since 382 BC.
阅读量:6104 次
发布时间:2019-06-20

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

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): 1895    Accepted Submission(s): 1084

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.
 
 
题意:每一个巫师去买魔杖,我们知道她喜欢的魔杖的种类,一个巫师只能买一种魔杖,现在你是卖魔杖的,我们要求买的魔杖数最多,求最多卖多少魔杖
思路:二分图的最大匹配数
代码:
#include
#include
#include
#include
#include
#define N 1010using namespace std;bool vis[N];int n,m,k,x,ans,girl[N],map[N][N];int read(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') {
if(ch=='-') f=-1; ch=getchar();} while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();} return x*f;}int find(int x){ for(int i=1;i<=n;i++) { if(!vis[i]&&map[x][i]) { vis[i]=true; if(girl[i]==-1||find(girl[i])){girl[i]=x; return 1;} } } return 0;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { ans=0; memset(map,0,sizeof(map)); memset(girl,-1,sizeof(girl)); for(int i=1;i<=m;i++) { k=read(); while(k--){x=read(); map[i][x]=1;} } for(int i=1;i<=m;i++) { memset(vis,0,sizeof(vis)); if(find(i)) ans++; } printf("%d\n",ans); } return 0;}

 

转载于:https://www.cnblogs.com/z360/p/7425109.html

你可能感兴趣的文章
老男孩教育每日一题-第107天-简述你对***的理解,常见的有哪几种?
查看>>
Python学习--time
查看>>
在OSCHINA上的第一篇博文,以后好好学习吧
查看>>
高利率时代的结局,任重道远,前途叵测
查看>>
Debian 6.05安装后乱码
查看>>
欢迎大家观看本人录制的51CTO精彩视频课程!
查看>>
IntelliJ IDEA中设置忽略@param注释中的参数与方法中的参数列表不一致的检查
查看>>
关于软件开发的一些感悟
查看>>
uva 10806
查看>>
纯CSS3绘制的黑色图标按钮组合
查看>>
Linux中环境变量文件及配置
查看>>
从0开始学Flutter
查看>>
mysql操作入门基础之对数据库和表的增删改查
查看>>
IIS负载均衡
查看>>
分布式事务,EventBus 解决方案:CAP【中文文档】
查看>>
Linux下的CPU性能瓶颈分析案例
查看>>
spring mvc入门
查看>>
2012在数据库技术会议上的讲话PPT打包
查看>>
【Android】 TextView设置个别字体样式
查看>>
python svn
查看>>