POJ 1469COURSES
来源:互联网 发布:js获取当前时间格式化 编辑:程序博客网 时间:2024/06/05 22:45
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
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 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抣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.
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抣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
23 33 1 2 32 1 21 13 32 1 32 1 31 1
Sample Output
YESNO
题目描述
n个学生去p个课堂,每一个学生都有自己的课堂,并且每个学生只能去一个课堂,题目要求能够安排每一个课堂都有人吗?
输入输出格式
输入格式:第一行是测试数据的个数,
每组测试数据的开始分别是p和n,
接着p行,每行的开始是这个课堂的学生人数m,接着m个数代表该课堂的学生编号
输出格式:如果该组数据能够这样安排就输出YES,否则输出NO。
输入输出样例
输入样例#1:
23 33 1 2 32 1 21 13 32 1 32 1 31 1
输出样例#1:
YESNO
说明
对于100%的数据,n≤100,m≤300
二分图最大匹配问题,匈牙利算法。
但莫名炸了一个点。。。
对拍了半小时,终于发现是 读入优化 的锅。。。
附代码:
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#define MAXN 110#define MAXM 310using namespace std;int t,n,p,ans;int f[MAXM],a[MAXN][MAXM];bool vis[MAXM];bool find(int x){ for(int i=1;i<=n;i++){ if(!vis[i]&&a[x][i]){ vis[i]=true; if(f[i]==-1||find(f[i])){ f[i]=x; return true; } } } return false;}int main(){ int x,y; scanf("%d",&t); while(t--){ memset(a,0,sizeof(a)); memset(f,-1,sizeof(f)); memset(vis,false,sizeof(vis)); scanf("%d%d",&p,&n); if(p>n){ printf("NO\n"); continue; } for(int i=1;i<=p;i++){ scanf("%d",&x); for(int j=1;j<=x;j++){ scanf("%d",&y); a[i][y]=1; } } ans=0; for(int i=1;i<=p;i++){ memset(vis,false,sizeof(vis)); if(find(i)) ans++; } if(ans==p)printf("YES\n"); else printf("NO\n"); } return 0;}
阅读全文
0 0
- POJ 1469 courses
- POJ-1469 COURSES
- POJ 1469 COURSES
- poj 1469 && hdu1083 COURSES
- POJ 1469 COURSES
- poj(1469)COURSES
- POJ-1469-COURSES
- POJ 1469 COURSES
- poj 1469 COURSES
- POJ 1469 COURSES
- poj 1469 COURSES
- POJ 1469:COURSES
- POJ 1469 COURSES
- poj 1469 COURSES 题解
- POJ 1469 COURSES
- poj 1469 COURSES
- POJ 1469 COURSES
- poj 1469COURSES
- 第一篇博客之Android编译环境配置---离线Gradle
- 学习水晶头制作
- 顺序表的相关操作
- Dubbo学习总结
- Qt5学习-模板库、工具类、控件-1
- POJ 1469COURSES
- VHDL中信号与变量的区别及赋值的讨论
- psql -W
- 第K小数(二分)
- LeetCode85 Maximal Rectangle
- Gourmet and Banquet CodeForces
- 匈牙利板子
- 笔试题:如何判断单链表是否存在环
- 升为主程序,总希望总结点什么