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. gulp自动化构建工具使用

    gulpfile.js: var gulp = require("gulp"); var imagemin = require("gulp-imagemin") ...

  2. 实用工具特别推荐 BGInfo

    https://docs.microsoft.com/en-us/sysinternals/downloads/bginfo 介绍 您在办公室中走过多少次,需要点击几个诊断窗口,提醒自己其配置的重要方 ...

  3. 原创 :单刷深渊 在Linux中系统安装mysql实战直播

    [root@web108 tools]# ###开始装mysql 1添加用户 [root@web108 tools]# useradd -s /sbin/nologin -M mysql 2解压 [r ...

  4. 富通天下(W 笔试)

    纸质算法题目 1.给你一个字符串,找出其中第一个只出现过一次的字符及其位置 正解:一层for循环,循环按序取出字符串中的单个字符,循环体内部使用String类的indexOf(),从当前字符下标往后搜 ...

  5. flask学习规划

    实现基本登录注册: 留言板功能: 并且部署到服务器: 预计完成时间6.16:. 后续页面美化: 各种其他功能的探索一个月时间: 并行地学习python,java,css,html,js,sql 暑假预 ...

  6. python json.loads json.dumps的区别

    json.loads() 是将字符串传化为字典 json.dumps () 是将字典转化为字符串 >>> dict = "{8:'bye', 'you':'coder'}& ...

  7. HTML中pre标签的用法

    我们经常会在要保持文本格式的时候使用pre标签,比如当我们要展示源代码的时候,只要放一个pre标签,然后把源代码直接复制,粘贴,然后在页面上就可以保持好格式.不会像放在其它标签里那样,把换行和空格都自 ...

  8. 将中文库导入到ARM板子中以解决中文显示乱码的教程

    1.将中文字符集导入到ARM板子中的/usr/fonts/目录下 在这里我们使用的字符集为:DroidSansFallback.ttf 下载地址为:https://pan.baidu.com/s/1e ...

  9. MySQL Utilities管理工具

    前提: 1.安装MySQL Utilities工具 2.复制my_print_defaults命令至/usr/bin下或写入环境变量. 卸载方式: python ./setup.py clean -- ...

  10. Docker客户端连接Docker Daemon的方式

    Docker为C/S架构,服务端为docker daemon,客户端为docker.service,支持本地unix socket域套接字通信与远程socket通信. 默认为本地unix socket ...