HUD——1083   Courses

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7699    Accepted Submission(s):
3781

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
Source
 
题目大意:
需要选一个学生集合,这个集合满足:1.每个学生仅能代表一门学科  2.每门学科都需要一名学生来代表 ; 求是否存在这样的一个集合存在输出yes否则输出no
思路:
完美的一个模板题,判断一下最大匹配数是否等于课程数就ok了。
代码:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 501
using namespace std;
bool vis[N];
int n,m,x,y,T,t,ans,pre[N],map[N][N];
int read()
{
    ,f=;char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
int find(int x)
{
    ;i<=n;i++)
    {
        if(!vis[i]&&map[x][i])
        {
            vis[i]=true;
            ||find(pre[i]))
            {
                pre[i]=x;
                ;
            }
        }
    }
    ;
}
int main()
{
    T=read();
    while(T--)
    {
        ans=;
        memset(map,,sizeof(map));
        m=read(),n=read();
        ;i<=m;i++)
        {
            t=read();
            while(t--)
            {x=read();map[i][x]=;}
        }
        if(n<m) printf("NO\n");
        else
        {
            memset(pre,-,sizeof(pre));
            ;i<=m;i++)
            {
                memset(vis,,sizeof(vis));
                if(find(i)) ans++;
            }
        //    printf("%d\n",ans);
            if(ans==m) printf("YES\n");
            else printf("NO\n");
        }
    }
    ;
}

HUD——1083 Courses的更多相关文章

  1. HDU 1083 Courses 【二分图完备匹配】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1083 Courses Time Limit: 20000/10000 MS (Java/Others)  ...

  2. HDU 1083 - Courses - [匈牙利算法模板题]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1083 Time Limit: 20000/10000 MS (Java/Others) M ...

  3. HDOJ 1083 Courses

    Hopcroft-Karp算法模板 Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  4. hdoj 1083 Courses【匈牙利算法】

    Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  5. hdu - 1083 - Courses

    题意:有P门课程,N个学生,每门课程有一些学生选读,每个学生选读一些课程,问能否选出P个学生组成一个委员会,使得每个学生代言一门课程(他必需选读其代言的课程),每门课程都被一个学生代言(1 <= ...

  6. HDU - 1083 Courses /POJ - 1469

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

  7. HDU 1083 Courses(二分图匹配模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1083 题意:有p门课和n个学生,每个学生都选了若干门课,每门课都要找一个同学来表演,且一个同学只能表演一门课,判 ...

  8. hdu 1083 Courses (最大匹配)

    CoursesTime Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  9. HDU 1083 Courses(最大匹配模版题)

    题目大意: 一共有N个学生跟P门课程,一个学生可以任意选一 门或多门课,问是否达成:    1.每个学生选的都是不同的课(即不能有两个学生选同一门课)   2.每门课都有一个代表(即P门课都被成功选过 ...

随机推荐

  1. 自欺欺人的使用 NSTimer 销毁

    自欺欺人的使用 NSTimer 销毁 Demo地址 1.NSTimer是要加到runloop中才会起作用. 常见的创建timer方式 // 第一种方式 @property (nonatomic , s ...

  2. ubuntu上部署windows开发的dotnet core程序

    目标:完成windows上开发的dotnet core程序部署至linux服务器上(Ubuntu 14.04) windows上开发dotnet core很简单,安装好VS2017,建立相关类型的项目 ...

  3. TensorFlow低阶API(三)—— 变量

    简介 TensorFlow变量是表示程序处理的共享持久状态的最佳方法. 我们使用tf.Variable类操作变量.tf.Variable表示可通过其运行操作来改变其值的张量.与tf.Tensor对象不 ...

  4. class 写在 import的位置 类的名字第一个字母大写 后面没括号 ES6

    class 写在 import的位置 类的名字第一个字母大写 后面没括号 class ObTableDataClass {}或者 const ObTableDataClass = class { in ...

  5. 编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数1/1+1/3+...+1/n(利用指针函数)

    *题目:编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数1/1+1/3+...+1/n(利用指针函数) public class 第三十九题按条件计算 ...

  6. OpenCV2:第十章 视频操作

    一.简介 OpenCV提供了专门操作视频的接口类VideoCapture 二.构造VideoCapture类 VideoCapture::VideoCapture() VideoCapture::Vi ...

  7. 单片微机原理P1:80C51指令系统和编程方法

    0. 寻址方式 寻址方式在汇编中是很重要的,汇编所有的操作都是和和内存或者寄存器打交道的,在80C51里面一共7种寻址方式.   1. 立即寻址: 这个没什么好说的,就是往寄存器或者内存里面写立即数, ...

  8. ffmpeg mp4 mp3 wav flac webm aac ac3 ogg格式转换

    版权声明:本文为博主原创文章,未经允许不得转载. ffmpeg是Linux中转换音频视频文件的常用工具. mp4 to mp3: ffmpeg -i $ID.mp4 -acodec libmp3lam ...

  9. 条款8:别让异常逃离析构函数(prevent exception from leaving destructors)

    NOTE: 1.析构函数绝对不要吐出异常.如果一个被析构函数调用的函数可能抛出异常,析构函数应该扑捉任何异常,然后吞下他们(不传播)或结束程序. 2.如果客户需要对某个操作函数运行期间抛出的异常做出反 ...

  10. Python开发环境之pyenv环境搭建

    首先到Github上下载Pyenv相应的一键安装脚本, 安装完毕,设置环境变量,设置环境变量,可以添加到个人家目录的.bashrc或.bash_profile及系统的全局的/etc/profile, ...