2019独角兽企业重金招聘Python工程师标准>>>

COURSES

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 16121 Accepted: 6339

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 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

Source

Southeastern Europe 2000

[Submit]   [Go Back]   [Status]   [Discuss]

我的解答:

不清楚每个学生是不是一定要分到课,只考虑每个课都得分到学生,过了.二分图,匈牙利算法.

/*=============================================================================
#     FileName: 1469.cpp
#         Desc: poj 1469
#       Author: zhuting
#        Email: cnjs.zhuting@gmail.com
#     HomePage: my.oschina.net/locusxt
#      Version: 0.0.1
#    CreatTime: 2013-12-07 18:21:46
#   LastChange: 2013-12-07 18:21:46
#      History:
=============================================================================*/
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#define maxp 105 /*courses*/
#define maxn 305 /*student*/bool mymap[maxp][maxn] = {0};
bool cover[maxn] = {0};
int link_[maxn] = {0};
int n = 0, p = 0;/*p = course_num, n = student_num*/bool find(int x)
{for (int i = 0; i < n; ++i){if (!cover[i] && mymap[x][i]){cover[i] = 1;if (link_[i] == -1 || find(link_[i])){link_[i] = x;return 1;}}}return 0;
}void init()
{memset(mymap, 0, sizeof(mymap));memset(cover, 0, sizeof(cover));memset(link_, 0xff, sizeof(link_));return;
}int main()
{int t = 0;int link__num = 0;int tmp = 0;scanf("%d", &t);while(t--){int ans = 0;init();scanf("%d%d", &p, &n);for(int i = 0; i < p; ++i){scanf("%d", &link__num);for (int j = 0; j < link__num; ++j){scanf("%d", &tmp);mymap[i][tmp - 1] = 1;}}for (int i = 0; i < p; ++i){memset(cover, 0, sizeof(cover));if (find(i)) ++ans;}//printf("%d\n", ans);if (ans == p) printf("YES\n");else printf("NO\n");}return 0;
}

转载于:https://my.oschina.net/locusxt/blog/182355

poj 1469 COURSES相关推荐

  1. poj 1469 COURSES 解题报告

    题目链接:http://poj.org/problem?id=1469 题目意思:有 N 个人,P个课程,每一个课程有一些学生参加(0个.1个或多个参加).问 能否使得 P 个课程 恰好与 P 个学生 ...

  2. 利用匈牙利算法Hopcroft-Karp算法解决二分图中的最大二分匹配问题 例poj 1469 COURSES...

    首先介绍一下题意:已知,有N个学生和P门课程,每个学生可以选0门,1门或者多门课程,要求在N个学生中选出P个学生使得这P个学生与P门课程一一对应. 这个问题既可以利用最大流算法解决也可以用匈牙利算法解 ...

  3. POJ - 1469 COURSES (匈牙利算法入门题)

    题意: P门课程,N个学生.给出每门课程的选课学生,求是否可以给每门课程选出一个课代表.课代表必须是选了该课的学生且每个学生只能当一门课程的. 题解: 匈牙利算法的入门题. #include < ...

  4. POJ 1469 COURSES 二分图最大匹配

    就是判断一下是不是每一个课程都能找到自己的代表人,做一遍最大匹配看看匹配数是否等于p即可 #include <cstdio> #include <cstring> #inclu ...

  5. poj 1469 二分图最大匹配

    就是最简单的最大匹配,没的说 #include<iostream> #include<cstdio> #include<cstring> #include<a ...

  6. POJ 1469 匈牙利算法

    匈牙利算法. 在于不停的找增广路. #include<iostream> #include<cstdio> #include<iostream> #include& ...

  7. poj 1469(二分图最大匹配)

    题意:学生和课程构成二部图,然后需要找到一个集合每个学生代表一门课,每一门课有一个学生代表. 思路:二分图入门题.当最大匹配等于课程数的时候可以找到集合. 代码如下: 1 /************* ...

  8. 二分图的最大匹配—匈牙利算法

    [基本概念]: 二分图: 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j分 ...

  9. 二分图匹配----匈牙利算法之二

    poj 1469 COURSES //题意:现在有p门课程和n个学生,现在需要有由p个学生组成的组织,该组织满足每个学生代表一门课程以及每门课程只能由一个学生代表, //现给出每门课程都有哪些学生可以 ...

最新文章

  1. 学会这21条,你离Vim大神就不远了
  2. 5G时代下,边缘计算产品的未来展望
  3. k8s 关键字以及管理流程。
  4. python计算两个数乘积_如何用PYTHON使两个数字总和变成乘积
  5. windows生成dump文件
  6. 漫画 | 面试的我 VS 真实的我
  7. python 趣味编程课_青少年编程:Python趣味编程基础入门课程
  8. SEO网站优化团队官网模板
  9. php7 viewmodel,ViewModel浅析
  10. 【资源】领域自适应相关论文、代码分享
  11. 注意!你手持身份证拍的照片,可能已经被炒到了上千元
  12. hdu 3642 Get The Treasury(扫描线)
  13. label之间展示间距_工法样板如何做?碧桂园质量工法样板展示区做法标准
  14. 学习OpenCV研究报告指出系列(二)源代码被编译并配有实例project
  15. Unity物体跟随鼠标移动
  16. DateTimeFormatter获取时间戳
  17. [数学学习笔记]极限的概念.
  18. vb标准(一):用户界面的设计
  19. java的关键业绩指标_SpreadJS前端开发案例:如何利用Javasrcipt创建财务关键业绩指标表...
  20. Laravel配置系统默认Log路径--Star.hou

热门文章

  1. Neural Representation Learning in NLP | 实录·PhD Talk #07
  2. 使用链路聚合进行负载分担
  3. 关于 eclipse startexplorer插件 快速打开文件夹
  4. (linux)查看及修改文件权限以及相关
  5. 响应用户呼声 币安更正BCH简称
  6. ['1','2','3'].map(parseInt)
  7. (原創) 如何正確的使用迴圈(使用for_each)? (C/C++) (STL) (template)
  8. html5实现获取地理位置信息并定位
  9. C# 实现FTP上传与下载
  10. 【独家】深度学习论文阅读路线图