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. 尝试使用Java6API读取java代码

    主要类:JavaCompiler  FileManager JavaCompiler .CompilationTaskAbstractProcessor参考代码https://today.java.n ...

  2. Java源代码分析与生成

    源代码分析:可使用ANTLRANTLR是开源的语法分析器,可以用来构造自己的语言,或者对现有的语言进行语法分析. JavaParser 对Java代码进行分析 CodeModel 用于生成Java代码 ...

  3. php返回json数据函数实例

    本文实例讲述了php返回json数据函数的用法,分享给大家供大家参考.具体方法如下: json_encode()函数用法: ? 1 echo json_encode(array('a'=>'bb ...

  4. Dom学习笔记-(一)

    一.概述 DOM(文档对象模型)是针对HTML和XML文档的一个API,其脱胎于DHTML. DOM可以将任意HTML和XML文档描绘成一个由多层节点构成的结构. 每一个文档包含一个根节点-文档节点, ...

  5. 运行avalon.define()发生的事情

      avalon.define = function(id, factory) { var $id = id.$id || id if (!$id) { log("warning: vm必须 ...

  6. 第 7 章 门面模式【Facade Pattern】

    以下内容出自:<<24种设计模式介绍与6大设计原则>> 好,我们继续讲课.大家都是高智商的人,都写过纸质的信件吧,比如给女朋友写情书什么的,写信的过程大家都还记得吧,先写信的内 ...

  7. Android手机上监听短信的两种方式

    Android手机上监听短信有两种方式: 1. 接受系统的短信广播,操作短信内容. 优点:操作方便,适合简单的短信应用. 缺点:来信会在状态栏显示通知信息. AndroidManifest.xml: ...

  8. Android sqlite 数据库在java代码中的增删改查

    private void queryPerson(PersonSQLiteOpenHelper personSQLiteOpenHelper) { SQLiteDatabase sqLiteDatab ...

  9. 李洪强漫谈iOS开发[C语言-031]-逻辑短路

  10. Altium Designer10 如何导出Gerber文件

    版本:AD10.818 目的:Gerber文件导出备忘 http://blog.sina.com.cn/s/blog_9b9a51990100zyyv.html 目录: Step1:设置原点 Step ...