HDU_1068_Girls and Boys_二分图匹配
Girls and Boys
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10132 Accepted Submission(s):
4660
study on the romantic relations between the students. The relation “romantically
involved” is defined between one girl and one boy. For the study reasons it is
necessary to find out the maximum set satisfying the condition: there are no two
students in the set who have been “romantically involved”. The result of the
program is the number of students in such a set.
The input contains
several data sets in text format. Each data set represents one set of subjects
of the study, with the following description:
the number of
students
the description of each student, in the following
format
student_identifier:(number_of_romantic_relations) student_identifier1
student_identifier2 student_identifier3
...
or
student_identifier:(0)
The student_identifier is an integer
number between 0 and n-1, for n subjects.
For each given data set, the
program should write to standard output a line containing the result.
2
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<vector>
- #include<algorithm>
- using namespace std;
- int map[][],t;
- int link[],vis[];
- int dfs(int x)
- {
- for(int i=; i<t; i++)
- if(map[x][i]==)
- if(vis[i]==)
- {
- vis[i]=;
- if(link[i]==-||dfs(link[i]))
- {
- link[i]=x;
- return ;
- }
- }
- return ;
- }
- int solve()
- {
- int ans=;
- memset(link,-,sizeof(link));
- for(int i=; i<t; i++)
- {
- memset(vis,,sizeof(vis));
- if(dfs(i))
- ans++;
- }
- return ans;
- }
- int main()
- {
- while(scanf("%d",&t)!=EOF)
- {
- memset(map,,sizeof(map));
- for(int i=; i<t; i++)
- {
- int n,n1,num;
- scanf("%d: (%d)",&n1,&n);
- for(int j=; j<n; j++)
- {
- scanf("%d",&num);
- map[i][num]=;
- }
- }
- int ans=solve();
- //cout<<ans<<endl;
- printf("%d\n",t-ans/);
- }
- return ;
- }
HDU_1068_Girls and Boys_二分图匹配的更多相关文章
- UVA 12549 - 二分图匹配
题意:给定一个Y行X列的网格,网格种有重要位置和障碍物.要求用最少的机器人看守所有重要的位置,每个机器人放在一个格子里,面朝上下左右四个方向之一发出激光直到射到障碍物为止,沿途都是看守范围.机器人不会 ...
- POJ 1274 裸二分图匹配
题意:每头奶牛都只愿意在她们喜欢的那些牛栏中产奶,告诉每头奶牛愿意产奶的牛棚编号,求出最多能分配到的牛栏的数量. 分析:直接二分图匹配: #include<stdio.h> #includ ...
- BZOJ1433 ZJOI2009 假期的宿舍 二分图匹配
1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2375 Solved: 1005[Submit][Sta ...
- HDU1281-棋盘游戏-二分图匹配
先跑一个二分图匹配,然后一一删去匹配上的边,看能不能达到最大匹配数,不能这条边就是重要边 /*----------------------------------------------------- ...
- HDU 1083 网络流之二分图匹配
http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...
- hdu 5727 Necklace dfs+二分图匹配
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...
- BZOJ 1059 & 二分图匹配
题意: 判断一个黑白染色的棋盘能否通过交换行或列使对角线上都是黑色. SOL: 真是有点醉...这种问题要么很神要么很水...第一眼感觉很水但就是不造怎么做...想了10分钟怎么感觉就是判断个数够不够 ...
- 【POJ 3020】Antenna Placement(二分图匹配)
相当于用1*2的板覆盖给定的h*w的格子里的点,求最少的板.可以把格子相邻的分成两个集合,如下图,0为一个集合,1的为一个,也就是(行数+列数)为奇数的是一个集合,为偶数的为另一个集合.1010101 ...
- BZOJ-1143&&BZOJ-2718 祭祀river&&毕业旅行 最长反链(Floyed传递闭包+二分图匹配)
蛋蛋安利的双倍经验题 1143: [CTSC2008]祭祀river Time Limit: 10 Sec Memory Limit: 162 MB Submit: 1901 Solved: 951 ...
随机推荐
- SpringMVC断言--Assert
Web 应用在接受表单提交的数据后都需要对其进行合法性检查,如果表单数据不合法,请求将被驳回.类似的,当我们在编写类的方法时,也常常需要对方法入参进行合 法性检查,如果入参不符合要求,方法将通过抛出异 ...
- PHP array_merge()
定义和用法 array_merge() 函数把两个或多个数组合并为一个数组. 如果键名有重复,该键的键值为最后一个键名对应的值(后面的覆盖前面的).如果数组是数字索引的,则键名会以连续方式重新索引. ...
- linux中man手冊的高级使用方法
Linux提供了丰富的帮助手冊.当你须要查看某个命令的參数时不必到处上网查找.仅仅要man一下就可以. Linux 的man手冊共同拥有下面几个章节: 1.Standard commands (标准命 ...
- JavaScript使用正則表達式
2.0 简单介绍 正則表達式是能够用来查找与给定模式匹配的文本的搜索模式.比如,在上一章中,我们在一个较长的字符串中查找子字符串Cookbook: var testValue = "This ...
- MyEclipse 9.0 正式版公布新闻 下载
MyEclipse 9.0 正式版公布 新闻 ============================================================================ ...
- vim学习笔记(1)——vim操作
仅记录一些自己最经常使用的vim操作.随时更新 文本操作 d 剪切.双击剪切一行 y 复制,双击复制一行 p 粘贴 x 删除当前光标下字符 r 替换当前光标字符.后面接替换的字符 :s/old/new ...
- POJ 3268 最短路应用
POJ3268 题意很简单 正向图跑一遍SPFA 反向图再跑一边SPFA 找最大值即可. #include<iostream> #include<cstdio> #includ ...
- JSP-Runoob:JSP XML 处理数据
ylbtech-JSP-Runoob:JSP XML 处理数据 1.返回顶部 1. JSP XML 数据处理 当通过HTTP发送XML数据时,就有必要使用JSP来处理传入和流出的XML文档了,比如RS ...
- bzoj4668
并查集+最小生成树 首先我们发现这题可以lct维护最小生成树,但是发现如果生成树在之后是不会修改的,那么就想到了并查集,然后就不知道怎么做了... 其实当我们连接两个连通块的时候,两个连通块只能通过这 ...
- [Swift通天遁地]二、表格表单-(18)快速应用多种预定义格式的表单验证
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...