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 ...
随机推荐
- C#百度图片识别API调用返回数据包解析
百度图片识别api接口 public static JObject GeneralBasic(string apikey,string secretkey,string path) { var cli ...
- c#一个统计运行时间方法
public string STD(int HowManySecond) { ) { "; } string ShowStr = ""; * )) { ShowStr + ...
- ftp上传文件异常
ftp一个服务器 如果是22端口 ssh-2.0-openssh_4.3 ,是什么意思? ftp服务用的是20.21端口,客户端添加ftp信息的时候输入的是21端口 ssh服务用的是22端口,应用于远 ...
- wait()和sleep()的区别
wait()是Object类的方法,当一个线程执行到wait()方法时,该线程就进入到一个和该线程相关的等待池中,同时释放了对象锁(暂时失去对象锁,wait(long timeout)超时时间到后还需 ...
- Netty 源码(二)NioEventLoop 之 Channel 注册
Netty 源码(二)NioEventLoop 之 Channel 注册 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 一 ...
- 学习python 多进程和多线程
''' 学习多进程和多线程 ''' import multiprocessing def deadLoop(): while True: pass if __name__ == '__main__': ...
- js之function
function* function* 这种声明方式(function关键字后跟一个星号)会定义一个生成器函数 (generator function),它返回一个 Generator 对象. 你 ...
- 协程的NullReferenceException 错误
public void loadPic(string url) { WWW www = new WWW(url); StartCoroutine(WaitForRequest(www)); } IEn ...
- 33、iOS10 由于权限问题导致崩溃的大坑
控制台报忠告: This app has crashed because it attempted to access privacy-sensitive data without a usage d ...
- TortoiseGit使用笔记
不喜欢敲命令行,或者用惯TortoiseSVN的也可以使用TortoiseGit 1. TortoiseGit安装 安装很简单,默认安装就可以.需要安装以下几个软件: l Git-2.14.3-64- ...