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. MIS框架开发计划

    计划开发模块 缓存模块 全球化模块(时间转换.货币转换.语言切换.度量转换.时区转换) 用户模块 用户短消息模块 日志模块(系统日志.用户操作日志.安全审计日志) 权限模块 配置模块 事件模块(观察者 ...

  2. datatables完整的增删改查

    1.需要指定datatables的ID <button class="btn btn-primary" id="newAttribute">新增证照 ...

  3. Mysql修改设置root密码的命令及方法

    方法一:使用SQL语句命令UPDATE 需用到Mysql自带的加密函数PASSWORD(string),该函数对一个明文密码进行加密,但不能解密.专门用于mysql.user(用户权限表)中设置密码, ...

  4. AppDomain(1)-AppDomainSetup

  5. 递归-快速排序quickSort

    现在对“6  1  2 7  9  3  4  5 10  8”这个10个数进行排序.首先在这个序列中随便找一个数作为基准数.为了方便,就让第一个数6作为基准数吧.接下来,需要将这个序列中所有比基准数 ...

  6. nutch 很多url unfetched的原因

    bin/hadoop jar apache-nutch-1.7.job org.apache.nutch.crawl.CrawlDbReader crawl/crawldb -stats -sort ...

  7. 高级PHP应用程序漏洞审核技术

    前言 PHP是一种被广泛使用的脚本语言,尤其适合于web开发.具有跨平台,容易学习,功能强大等特点,据统计全世界有超过34%的网站有php的应 用,包括Yahoo.sina.163.sohu等大型门户 ...

  8. NAT(NAPT)地址转换过程

    整理自NAT地址转换过程 注:本文实质讲的是NAPT(Network Address Port Translation),即网络端口地址转换.NAPT与动态地址NAT不同,它将内部连接映射到外部网络中 ...

  9. 系统的了解DJANGO中数据MODULES的相关性引用

    数据库结构如下: from django.db import models class Blog(models.Model): name = models.CharField(max_length=1 ...

  10. "NetworkError: 500 Internal Server Error - http://develop.console.aliyun.sinopec.com/ots/ots_queryOtsList.action?state=0"

    项目明明开始好好的,报的这个错,错误提示也很少,啥信息都没有,只是明白是服务器报了500,知道是服务器内部错误,但是却没法找不到问题所在.后来突然想到把下面报错的action直接在浏览器运行: htt ...