hdoj 1083 Courses【匈牙利算法】

时间:2022-03-18 20:42:58

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 - &lbrack;匈牙利算法模板题&rsqb;

    题目链接: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 &lpar; 匈牙利算法 dfs &plus; bfs &rpar;

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

  4. poj 1469 COURSES&lpar;匈牙利算法模板)

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

  5. hdoj 2063 过山车【匈牙利算法&plus;邻接矩阵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 &sol;POJ - 1469

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

  9. ACM&sol;ICPC 之 机器调度-匈牙利算法解最小点覆盖集&lpar;DFS&rpar;&lpar;POJ1325&rpar;

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

随机推荐

  1. jsvascript—谜之this?

    原文:Gentle explanation of ‘this’ keyword in JavaScript 1. 迷之 this 对于刚开始进行 JavaScript 编程的开发者来说,this 具有 ...

  2. kafka管理器kafka-manager部署安装

    运行的环境要求 Kafka 0.8.1.1+ sbt 0.13.x Java 7+ 功能 为了简化开发者和服务工程师维护Kafka集群的工作,yahoo构建了一个叫做Kafka管理器的基于Web工具, ...

  3. 巧遇&quot&semi;drwxr-xr-x&period;&quot&semi;权限

    drwxr-xr-x. 是SELinux的问题 REDHAT6之后安全提高所以设置的 关闭SELINUX就好了 因为新版本ls把多acl和selinux属性加进去了,与系统无关,新版本的ls代码使用1 ...

  4. DOM生成XML文档与解析XML文档&lpar;JUNIT测试&rpar;

    package cn.liuning.test; import java.io.File; import java.io.IOException; import javax.xml.parsers.D ...

  5. 【视频编解码&&num;183&semi;学习笔记】11&period; 提取SPS信息程序

    一.准备工作: 回到之前SimpleH264Analyzer程序,找到SPS信息,并对其做解析 调整项目目录结构: 修改Global.h文件中代码,添加新数据类型UINT16,之前编写的工程中,UIN ...

  6. mock js使用方法简单记录

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. JAVA初学者(一)

    2015-12-15 21:26:17 刚学的java  做个总结: 1.构造函数没有返回值. 2.A对象调用Q的方法,Q方法里的变量就是A的变量 Fraction add(Fraction f) 在 ...

  8. 【WXS数据类型】Object

    Object 是一种无序的键值对. 属性: 名称 值类型 说明 [Object].constructor [String] 返回值为“Object”,表示类型的结构字符串 方法: 原型:[Object ...

  9. Kibana6&period;x&period;x源码分析--如何使用kibana的savedObjectType对象

    默认kibana插件定义了三种保存实体对象[savedObjectType],如下图所示: 要使用只需要在自己定义的app的uses属性中添加上:savedObjectTypes  即可,如下图所示: ...

  10. 【spring data jpa】spring data jpa 中的update 更新字段,如果原字段值为null不处理,不为null则在原来的值上加一段字符串

    示例代码: /** * 如果barCode字段值为null则不处理 * 如果barCode字段值不为null则在原本值的前面拼接 del: * @param dealer * @return */ @ ...