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. BZOJ3143:[HNOI2013]游走——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=3143 Description 一个无向连通图,顶点从1编号到N,边从1编号到M. 小Z在该图上进行随 ...

  2. Spark获取某个手机号在某个基站下停留的时间和当前手机所在的位置的案例

    1.业务需求 在拥有手机号在每个基站处停留时间日志 和 基站信息的 算出某个手机号的(所在基站,停留时间),(当前所在经度,当前所在纬度) 其中手机连接基站产生的日志信息类似如下: 186888888 ...

  3. SDUT 3930 线段树

    皮卡丘的梦想2 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 一天,一只住在 501 实验 ...

  4. Redrain 通用菜单控件使用方法和说明(附源码和demo)

    转载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/42889709 大概半年前我写过博客说明怎么改造duilib的原代Menu ...

  5. Java中x=x+1 与x+=1 的一点区别

    转载自:http://www.cnblogs.com/heshan664754022/archive/2013/04/01/2994028.html 作者:十年半山 今天同悦姐学到了关于Java的复合 ...

  6. Eclipse srever起来时,时间超过45s。

    双击servere的名字,在属性界面上进行修改. 如下图: 修改TimeOut中的值即可.

  7. 数据结构&字符串:可持久化字典树

    利用可持久化Trie树实现范围内取值异或最大值 如果标题没有表达清楚意思,可以看这里的题干: 然后根据异或的性质,异或一个数两次相当于没有异或,那么我们可以维护一个异或前缀和 有了异或前缀和之后我们就 ...

  8. Linux Shell下执行sqlplus

    转载自: http://www.cnblogs.com/include/archive/2011/12/30/2307889.html 以下方法解决了在linux下自动的删除创建用户 sqlplus ...

  9. Item 5 避免创建不必要的对象

    场景一: 这个是经常出现的问题,因为我们经常误用String. public class Test { public static void main(String[] args) { //参数&qu ...

  10. 【Foreign】K优解 [堆]

    K优解 Time Limit: 20 Sec  Memory Limit: 512 MB Description 给定n个行数,每行m个.在每行中选出一个数来,求出前 k 小的异或和. Input 第 ...