Courses

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4175    Accepted Submission(s): 1990

Problem Description
Consider
a group of N students and P courses. Each student visits zero, one or
more than one courses. Your task is to determine whether it is possible
to form a committee of exactly P students that satisfies simultaneously
the conditions:

. 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:

 
Sample Input
 2
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1
Sample Output
YES
NO
 
Source
 
Recommend
/**
题意:n个student,m个course,然后每个course选一个课代表,然后看能否为每门course
选到一名课代表
做法:匈牙利算法
**/
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string.h>
using namespace std;
#define maxn 310
int linker[maxn];
int un,vn;
int g[maxn][maxn];
bool used[maxn];
int n,m;
int dfs(int u)
{
for(int i=;i<=m;i++)
{
if(g[u][i] && used[i] == false)
{
used[i] = true;
if(linker[i] == - || dfs(linker[i]))
{
linker[i] = u;
return ;
}
}
}
return ;
}
int hungary()
{
int res = ;
memset(linker,-,sizeof(linker));
for(int i=;i<n;i++)
{
memset(used,false,sizeof(used));
res += dfs(i);
}
return res;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int T;
scanf("%d",&T);
while(T--)
{ scanf("%d %d",&n,&m);
int Q;
memset(g,,sizeof(g));
int v;
for(int i=;i<n;i++)
{
scanf("%d",&Q);
while(Q--)
{
scanf("%d",&v);
g[i][v] = ;
}
}
int res = ;
res = hungary();
if(res == n) printf("YES\n");
else printf("NO\n");
}
return ;
}

HDU-1083的更多相关文章

  1. HDU 1083 网络流之二分图匹配

    http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...

  2. hdu - 1083 - Courses

    题意:有P门课程,N个学生,每门课程有一些学生选读,每个学生选读一些课程,问能否选出P个学生组成一个委员会,使得每个学生代言一门课程(他必需选读其代言的课程),每门课程都被一个学生代言(1 <= ...

  3. HDU - 1083 Courses /POJ - 1469

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 http://poj.org/problem?id=1469 题意:给你P个课程,并且给出每个课 ...

  4. HDU 1083 - Courses - [匈牙利算法模板题]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1083 Time Limit: 20000/10000 MS (Java/Others) M ...

  5. HDU 1083 Courses(二分图匹配模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1083 题意:有p门课和n个学生,每个学生都选了若干门课,每门课都要找一个同学来表演,且一个同学只能表演一门课,判 ...

  6. (匹配)Courses -- hdu --1083

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1083 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  7. HDU 1083 Courses 【二分图完备匹配】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1083 Courses Time Limit: 20000/10000 MS (Java/Others)  ...

  8. 【hdu 1083】Courses

    [Link]:http://acm.hdu.edu.cn/showproblem.php?pid=1083 [Description] 有p门的课,每门课都有若干学生,现在要为每个课程分配一名课代表, ...

  9. HDU 1083 Courses(最大匹配模版题)

    题目大意: 一共有N个学生跟P门课程,一个学生可以任意选一 门或多门课,问是否达成:    1.每个学生选的都是不同的课(即不能有两个学生选同一门课)   2.每门课都有一个代表(即P门课都被成功选过 ...

  10. C - Courses - hdu 1083(模板)

    一共有N个学生跟P门课程,一个学生可以任意选一 门或多门课,问是否达成: 1.每个学生选的都是不同的课(即不能有两个学生选同一门课) 2.每门课都有一个代表(即P门课都被成功选过) 输入为: P N( ...

随机推荐

  1. [bzoj] 3669 NOI2014 魔法森林 || LCT

    原题 copy一篇题解:原链接 将边按照a排序,然后从小到大枚举,加入图中. 在图中用lct维护一棵两点之间b最大值尽量小的生成树. 当加入一条边(u, v)时: 如果(u, v)不连通,则直接加入这 ...

  2. matlab特殊符号表

    Character Sequence Symbol Character Sequence Symbol Character Sequence Symbol \alpha α \upsilon υ \s ...

  3. URAL - 1627:Join (生成树计数)

    Join 题目链接:https://vjudge.net/problem/URAL-1627 Description: Businessman Petya recently bought a new ...

  4. 关于微信内置浏览器安卓端session丢失问题

    项目上线测试,发现微信安卓端存在用户登录无法验证session情况, 导致每次接口请求都无法识别,而苹果客户端不会出现此问题,非微信环境打开不会出现此问题,找到一些解决方案做下记录: 方案1: 由于微 ...

  5. 关于MyBatis一些小错误,元素内容必须由格式正确的字符数据或标记组成.

    今天在Mapper.xml文件写查询语句报了个奇怪的错误 Caused by: org.apache.ibatis.builder.BuilderException: Error creating d ...

  6. sql生成一个日期表

    SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Auth ...

  7. POJ 2891- Strange Way to Express Integers CRT 除数非互质

    题意:给你余数和除数求x 注意除数不一定互质 思路:不互质的CRT需要的是将两个余数方程合并,需要用到扩展GCD的性质 合并互质求余方程 m1x -+ m2y = r2 - r1 先用exgcd求出特 ...

  8. 通过gitlabAPI批量创建用户

    上午服务器领导通知我给服务器所有同事添加gitlab账号,服务器总共67个人,这要是一个一个在页面添加,我得累死,是否有其他的办法呢?有问题找google,果然是可以通过gitlab的API批量添加的 ...

  9. 省队集训 Day7 选点游戏

    [题目大意] 维护一个$n$个点的图,$m$个操作,支持两个操作: 1. 连接$(u, v)$这条边: 2. 询问$u$所在的联通块中,能选出的最大合法的点数. 一个方案是合法的,当且仅当对于所有被选 ...

  10. 汕头市队赛SRM 20 T3 灵魂觉醒

    背景 自从芽衣.布洛妮娅相继灵魂觉醒之后,琪亚娜坐不住了.自己可是第一个入驻休伯利安号的啊!于是她打算去找德丽莎帮忙,为她安排了灵魂觉醒的相关课程. 第一天,第一节课. “实现灵魂觉醒之前,你需要先将 ...