M - COURSES
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
Input
Your program should read sets of data from the std input. The first line of the input contains the number of the data sets. Each data set is presented in the following format:
P N
Count1 Student 1 1 Student 1 2 ... Student 1 Count1
Count2 Student 2 1 Student 2 2 ... Student 2 Count2
...
CountP Student P 1 Student P 2 ... Student P 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抣l 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.
Output
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.
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
判断每个课程能不能都匹配上人,二分图匹配
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=305;
int n,m;
int line[N][N],visit[N],connect[N];
bool find(int x)
{
rep(i,1,m+1)
{
if(line[x][i]&&visit[i]==0)
{
visit[i]=1;
if(connect[i]==0||find(connect[i]))
{
connect[i]=x;
return true;
}
}
}
return false;
}
int main()
{
int re,x,p;
sf("%d",&re);
while(re--)
{
int ans=0;
mm(line,0);
mm(connect,0);
sf("%d%d",&n,&m);
rep(i,1,n+1)
{
sf("%d",&p);
while(p--)
{
sf("%d",&x);
line[i][x]=1;
}
}
rep(i,1,n+1)
{
mm(visit,0);
if(find(i)) ans++;
}
if(ans==n) pf("YES\n");
else pf("NO\n");
}
return 0;
}
M - COURSES的更多相关文章
- poj 2239 Selecting Courses (二分匹配)
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8316 Accepted: 3687 ...
- POJ 1469 COURSES
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20478 Accepted: 8056 Descript ...
- HDOJ 1083 Courses
Hopcroft-Karp算法模板 Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- Courses
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- HDU-----(1083)Courses(最大匹配)
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- POJ 1469 COURSES(二部图匹配)
COURSES Time Limit: 1000MS Memory ...
- Doing well in your courses ---- a guide by Andrej Karpathy
Doing well in your courses a guide by Andrej Karpathy Here is some advice I would give to younger st ...
- Windows Kernel Security Training Courses
http://www.codemachine.com/courses.html#kerdbg Windows Kernel Internals for Security Researchers Thi ...
- poj 1469 COURSES(匈牙利算法模板)
http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- hdoj 1083 Courses【匈牙利算法】
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
随机推荐
- [原创]Robo 3T 1.2.1 工具使用介绍
[原创]Robo 3T 1.2.1 工具使用介绍 1 Robo 3T 1.2.1 简介 robo 3t 是一款MongoDB的辅助插件,可以帮助您在管理数据库内容以及数据库代码编辑方面提供一定的开发 ...
- Win 10 System Restore Fail 0x80070091
Question: Below about says it all. I tried SysRes from two points, both with same failure. System R ...
- HashMap问答
一.什么是HashMap二.HashMap的继承关系三.HashMap数据结构四.HashMap查找.添加元素是怎样的五.什么是Hash碰撞六.HashMap是线程安全的吗?七.HashMap怎样处理 ...
- layui常见问题记录
1.用js选中checkbox,没有效果 解决方式:加入 form.render(); 重新渲染表单 $(this).prop('checked', true); //在新版本的jquery中,如果是 ...
- 07、RDD持久化
为了避免多次计算同一个RDD(如上面的同一result RDD就调用了两次Action操作),可以让Spark对数据进行持久化.当我们让Spark持久化存储一个RDD时,计算出RDD的节点会分别保存它 ...
- [Python设计模式] 第20章 挨个买票——迭代器模式
github地址:https://github.com/cheesezh/python_design_patterns 迭代器模式 迭代器模式,提供一种方法顺序访问一个聚合对象中各个元素,而又不暴露该 ...
- Lombok 使用攻略
1. Lombok 简介 Lombok 可以通过简单的注解来帮助我们简化消除一些必须有但显得很臃肿的Java代码,通过使用对应的注解,可以在编译源码的时候生成对应的方法. Lombok 既是一个 ID ...
- 关于Android开发中Arm、X86和Mips(草稿)
一.架构 1.Arm架构 是一个32位精简指令集(RISC)处理器架构,其广泛地使用在许多嵌入式系统设计. 2.X86架构 是一个intel通用计算机系列的标准编号缩写,也标识一套通用的计算机指令集合 ...
- Kettle实现数据抽取、转换、装入和加载数据-数据转移ETL工具
原文地址:http://www.xue51.com/soft/5341.html Kettle是来自国外的一款开源的ETL工具,纯java编写,可以在Window.Linux.Unix上运行,绿色无需 ...
- mycat偶尔会出现JVM报错double free or corruption并崩溃退出
mycat偶尔会出现JVM报错double free or corruption并崩溃退出 没有复杂的sql,也没有大量的io INFO | jvm | // :: | *** Error in `j ...