Hdu1083 Courses
Courses
. every student in the committee represents a different course (a student can represent a course if he/she visits that course)
. each course has a representative in the committee
Your program should read sets of data from a text file. The first line of the input file contains the number of the data sets. Each data set is presented in the following format:
P N
Count1 Student1 1 Student1 2 ... Student1 Count1
Count2 Student2 1 Student2 2 ... Student2 Count2
......
CountP StudentP 1 StudentP 2 ... StudentP CountP
The first line in each data set contains two positive integers separated by one blank: P (1 <= P <= 100) - the number of courses and N (1 <= N <= 300) - the number of students. The next P lines describe in sequence of the courses . from course 1 to course P,
each line describing a course. The description of course i is a line that starts with an integer Count i (0 <= Count i <= N) representing the number of students visiting course i. Next, after a blank, you'll find the Count i students, visiting the course,
each two consecutive separated by one blank. Students are numbered with the positive integers from 1 to N.
There are no blank lines between consecutive sets of data. Input data are correct.
The result of the program is on the standard output. For each input data set the program prints on a single line "YES" if it is possible to form a committee and "NO" otherwise. There should not be any leading blanks at the start of the line.
An example of program input and output:
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1
NO
——————————————————————————————
题目的意思是给出n个学生想选的课标号,每个人只能选1门课,每门课只能被1个人选,问最大有几组配对关系
思路:将学生和他想选的课建边,然后跑最大二分图匹配
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
const int MAXN=1005;
int uN,vN; //u,v数目
int g[MAXN][MAXN];
int linker[MAXN];
bool used[MAXN];
int color[MAXN]; bool dfs(int u)
{
int v;
for(v=1; v<=vN; v++)
if(g[u][v]&&!used[v])
{
used[v]=true;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
return false;
} int hungary()
{
int res=0;
int u;
memset(linker,-1,sizeof(linker));
for(u=1; u<=uN; u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
} int main()
{
int m,n,x,y,T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
memset(g,0,sizeof g);
for(int i=1; i<=n; i++)
{
scanf("%d",&x);
for(int j=0;j<x;j++)
{
scanf("%d",&y);
g[i][y]=1;
}
}
uN=n,vN=m;
printf("%s\n",hungary()==n?"YES":"NO");
}
return 0;
}
Hdu1083 Courses的更多相关文章
- HDU1083 Courses —— 二分图最大匹配
题目链接:https://vjudge.net/problem/HDU-1083 Courses Time Limit: 20000/10000 MS (Java/Others) Memory ...
- HDU-1083 Courses 二分图 最大匹配
题目链接:https://cn.vjudge.net/problem/HDU-1083 题意 有一些学生,有一些课程 给出哪些学生可以学哪些课程,每个学生可以选多课,但只能做一个课程的代表 问所有课能 ...
- hdu2063+hdu1083(最大匹配数)
传送门:hdu2063过山车 #include <cstdio> #include <cstring> #include <string> #include < ...
- HDU1083 :Courses(二分图匹配)
Cources Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- poj 2239 Selecting Courses (二分匹配)
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8316 Accepted: 3687 ...
- POJ 1469 COURSES
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20478 Accepted: 8056 Descript ...
- HDOJ 1083 Courses
Hopcroft-Karp算法模板 Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- Courses
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- HDU-----(1083)Courses(最大匹配)
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
随机推荐
- js 箭头函数
箭头函数 ES6标准新增了一种新的函数:Arrow Function(箭头函数). x => x * x相当于: function (x) { return x * x; }箭头函数相当于匿名函 ...
- 在电脑上查看小米手机连接wifi时保存的密码
手机连接的wifi,想另一个手机也连上,密码忘了. 先备份手机的资料,然后将手机连上电脑,在SD卡上MIUI-backup-allbackup文件夹中, 找到刚才备份的文件夹 点进去找到WLAN设置. ...
- BZOJ1833或洛谷2602 [ZJOI2010]数字计数
BZOJ原题链接 洛谷原题链接 又是套记搜模板的时候.. 对\(0\sim 9\)单独统计. 定义\(f[pos][sum]\),即枚举到第\(pos\)位,前面枚举的所有位上是当前要统计的数的个数之 ...
- egg 为企业级框架和应用而生, 阿里出品
https://eggjs.org/zh-cn/intro/ egg 是什么? egg 为企业级框架和应用而生,我们希望由 egg 孕育出更多上层框架,帮助开发团队和开发人员降低开发和维护成本. 设计 ...
- Raw Socket(原始套接字)实现Sniffer(嗅探)
参考资料: https://www.xuebuyuan.com/3190946.html https://blog.csdn.net/zxygww/article/details/52093308 i ...
- csdn博客
https://blog.csdn.net/lydstory123?t=1 以前还有几篇文章 忘记了
- 会话和http请求
一次HTTP请求和响应的过程 域名解析 --> 发起TCP的3次握手 --> 建立TCP连接后发起http请求 --> 服务器响应http请求,浏览器得到html代码 --> ...
- Linux配置nodejs
http://my.oschina.net/blogshi/blog/260953 首先去官网下载代码,这里一定要注意安装分两种,一种是Source Code源码,一种是编译后的文件.我就是按照网上源 ...
- 生活类App原型制作分享-AnyList
AnyList是一款可以帮你创建购物清单,并且帮助你整理食谱的生活工具App,前面引导页采用图片+文字的方式,介绍App的用法,登录注册采用选项卡切换的方式,减少了页面切换的繁琐操作,在Mockplu ...
- flask部署
https://blog.csdn.net/zhuod/article/details/77850783