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 ...
随机推荐
- laravel框架一次请求的生命周期
第一件事所有的请求都会被web服务器(Apache/Nginx)导向public/index.php文件.index.php文件载入Composer生成的自动加载设置,然后从bootstrap/app ...
- iOS.CocoaPods.0
1. CocoaPods CocoaPods 是Objective-C (iOS and OS X) projects 的依赖管理器. A CocoaPod (singular) is a speci ...
- MFC窗口颜色的设置
本文主要介绍对话框背景色以及控件颜色的设置(SetDialogBkColor()不再被支持). 对话框背景色的设置 1.重载OnPaint()函数,即WM_PAINT消息,代码如下所示: void C ...
- [SoapUI] 从上一个测试步骤获取ID list,通过Groovy脚本动态生成 Data Source 供后面的步骤使用
https://support.smartbear.com/readyapi/docs/testing/data-driven/types/groovy.html 从官网拷贝code到SoapUI里面 ...
- JDK 规范目录
JDK 规范目录 1.1 Java 异常处理 2.1 JDK 之 NIO 2 WatchService.WatchKey(监控文件变化) https://mp.weixin.qq.com/s/NIn2 ...
- Netty 源码 Channel(二)主要类
Netty 源码 Channel(二)主要类 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 一.Channel 类图 二. ...
- 类名.class 与 类名.this 详解
类名.class 与 类名.this 详解 今天在看 PropertyPlaceholderConfigurer 源码时,突然看到一个 PropertyPlaceholderConfigurer.th ...
- oracle 视图带参数
-- create or replace package p_view_param is --参数一 function set_ID(num number) return number; functi ...
- EditText输入小数
edtValue.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
- AnsiToUtf8 和 Utf8ToAnsi
在服务端数据库的处理当中,涉及中文字符的结构体字段,需要转为Utf8后再存储到表项中.从数据库中取出包含中文字符的字段后,如果需要保存到char *类型的结构体成员中,需要转为Ansi后再保存.从数据 ...