hdoj 1083 Courses【匈牙利算法】
Courses
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4669 Accepted Submission(s):
2230
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:
#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【匈牙利算法】的更多相关文章
- HDU 1083 - Courses - [匈牙利算法模板题]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1083 Time Limit: 20000/10000 MS (Java/Others) M ...
- HDOJ 1083 Courses
Hopcroft-Karp算法模板 Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- POJ-1469 COURSES ( 匈牙利算法 dfs + bfs )
题目链接: http://poj.org/problem?id=1469 Description Consider a group of N students and P courses. Each ...
- poj 1469 COURSES(匈牙利算法模板)
http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- hdoj 2063 过山车【匈牙利算法+邻接矩阵or邻接表】
过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- POJ - 1469 COURSES (匈牙利算法入门题)
题意: P门课程,N个学生.给出每门课程的选课学生,求是否可以给每门课程选出一个课代表.课代表必须是选了该课的学生且每个学生只能当一门课程的. 题解: 匈牙利算法的入门题. #include < ...
- HDU 1083 Courses 【二分图完备匹配】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1083 Courses Time Limit: 20000/10000 MS (Java/Others) ...
- HDU - 1083 Courses /POJ - 1469
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 http://poj.org/problem?id=1469 题意:给你P个课程,并且给出每个课 ...
- ACM/ICPC 之 机器调度-匈牙利算法解最小点覆盖集(DFS)(POJ1325)
//匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring&g ...
随机推荐
- absolute之整体布局实现
要实现如图的布局,我最先想到是将header与footer绝对定位,但是发现在移动端会出现bug,经查资料发现用absolute实现整体布局非常好,还挺简单的. .header, .footer, . ...
- WORDPRESS插件开发学习(一)HELLO WORLD
WORDPRESS插件开发学习系列文章第一篇,在每篇文章的后面追加固定的字符“Hello World” 一.打开wordpress目录->wp-content->plugins 二.在pl ...
- JavaScript获取非行间样式/定义样式
html节点的样式分为以下几种 (1)浏览器默认样式 (2)引用样式(引用外部css文件的样式.style标签内定义的样式) 引用外部css样式:<link rel="styleshe ...
- 不能正确获得上次构建以来的Commit
不能正确获得上次构建以来的Commit 如何解决?
- mac中的xampp配置xdebug
[xdebug] zend_extension=/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/ ...
- express开发实例
express获取参数有三种方法:官网介绍如下 Checks route params (req.params), ex: /user/:id Checks query string params ( ...
- tpl demo
using System; using System.Collections.Concurrent; using System.Threading; using System.Threading.Ta ...
- 实现js的类似alert效果的函数
这个简单的类似alert的函数,效果还行,至于css样式,那没的说了,笔者确实尽力了,如果读者觉得太烂,你可以随便改函数的样式的,反正,笔者觉得还可以,呵呵. <!DOCTYPE html PU ...
- html 各个标签初始化
html,body,div,ul,li,ol,h1,h2,h3,h4,h5,h6,span,input{ margin:0;padding:0;}body{font:12px/1.5em " ...
- PS制作独特火焰立体文字
效果图中的文字部分并不复杂,为简单的立体字,用图层样式及手工复制就可以做好.火焰部分稍微有点复杂,用动感及火焰素材叠加,然后再加上火花及炫光等渲染出动感效果即可.最终效果 素材下载:本教程中需要用到的 ...