Courses

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

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
看到英文题就头疼,看不懂啊  伤心..........
  此题是说如果每门课都要有人选且选此课的人不能选择其他课则输出yes否则输出no
用匈牙利算法  如果最后配对出来的总对数等于总的课数则正确
#include<stdio.h>
#include<string.h>
#define MAX 1100
int cour,stu,p;
int map[MAX][MAX];
int vis[MAX],s[MAX];
int find(int x)
{
int i,j;
for(i=1;i<=stu;i++)
{
if(map[x][i]&&vis[i]==0)//如果学生对这门课程感兴趣且 没被标记
{ //(这里被标记就是说第i个学生选上了这门课)
vis[i]=1;
if(s[i]==0||find(s[i]))//如果第i个学生没有选上课或者可以换课
{
s[i]=x;//则让第i个学生选上这门课
return 1;
}
}
}
return 0;
}
int main()
{
int i,j,k,t,sum;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&cour,&stu);
memset(map,0,sizeof(map));
memset(s,0,sizeof(s));
for(i=1;i<=cour;i++)
{
scanf("%d",&p);
while(p--)
{
scanf("%d",&k);
map[i][k]=1;//给对应课程和对应学生标记
}
}
sum=0;
for(i=1;i<=cour;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
sum++;
}
if(sum==cour)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

  

 
 
 
 

hdoj 1083 Courses【匈牙利算法】的更多相关文章

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

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

  2. HDOJ 1083 Courses

    Hopcroft-Karp算法模板 Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  3. POJ-1469 COURSES ( 匈牙利算法 dfs + bfs )

    题目链接: http://poj.org/problem?id=1469 Description Consider a group of N students and P courses. Each ...

  4. poj 1469 COURSES(匈牙利算法模板)

    http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

  5. hdoj 2063 过山车【匈牙利算法+邻接矩阵or邻接表】

    过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. POJ - 1469 COURSES (匈牙利算法入门题)

    题意: P门课程,N个学生.给出每门课程的选课学生,求是否可以给每门课程选出一个课代表.课代表必须是选了该课的学生且每个学生只能当一门课程的. 题解: 匈牙利算法的入门题. #include < ...

  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 /POJ - 1469

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

  9. ACM/ICPC 之 机器调度-匈牙利算法解最小点覆盖集(DFS)(POJ1325)

    //匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring&g ...

随机推荐

  1. SqlServer日期(convert函数,getdate函数)

    SqlServer日期(convert函数,getdate函数) 函数GETDATE()的返回值在显示时只显示到秒.实际上,SQL Sever内部时间可以精确到毫秒级(确切地说,可以精确到3.33毫秒 ...

  2. php设计模式笔记:单例模式

    php设计模式笔记:单例模式 意图: 保证一个类仅有一个实例,并且提供一个全局访问点 单例模式有三个特点: 1.一个类只有一个实例2.它必须自行创建这个实例3.必须自行向整个系统提供这个实例 主要实现 ...

  3. 缓存 Cache

    Controllers层 public class HomeController : Controller    {        //        // GET: /Home/       // ...

  4. java MYSQL做分页

    MySql中查询语句实现分页功能 语句: select * from 表名 where 条件 limit 要找第几页,每页多少行; import java.util.*; import java.sq ...

  5. 运行 Docker 容器时的安全风险:别丢了你的套接字

    我们都遇到过这种情况:你只是想尝试一段命令行,但安装进程却如同抵押贷款申请那般繁琐.如果不是强制要求完成这么多步骤,你的开发环境会被永远不会再使用的库弄乱.自然, Docker 来了以后,你惊异地发现 ...

  6. OneAPM Cloud Test——系统性能监控神器

    2015 年 8 月,OneAPM 推出了一款系统性能监控产品--Cloud Test,产品上线以来以「两低一高」的特点迅速成为市场增长率最快的一匹黑马.「两低一高」,即低使用成本.低学习成本以及高服 ...

  7. 李洪强iOS开发之-环信02.1_环信 SDK 2.x到3.0升级文档

    李洪强iOS开发之-环信02.1_环信 SDK 2.x到3.0升级文档 SDK 2.x 至 3.0 升级指南 环信 SDK 3.0 升级文档 3.0 中的核心类为 EMClient 类,通过 EMCl ...

  8. [转贴]Windows下gSoap交叉编译环境的搭建

    本人直接就用过gSoap,它是用以C/C++写webservice的利器     交叉编译的时候,有两个很关键的程序:         soapcpp2.exe         wsdl2h.exe ...

  9. Android Training精要(五)讀取Bitmap對象實際的尺寸和類型

    讀取Bitmap對象實際的尺寸和類型 BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecode ...

  10. 【CF】174 Div.1 B Cow Program

    思路是树形DP+状态压缩.其实仅有2个状态,奇数次来到x或者偶数次来到x.(因为对x的更新不同).同时开辟visit数组,解决环.注意,一旦遇到环结果就是-1.DP数组存放第奇数/偶数次来到x时,对y ...