hdu1083二分图匹配模板题
. 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:
Input
2
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1
Output
YES
NO
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
第一题二分图啊,wa了6遍,后来a了还是不知道当时为啥wa了
题意:学科与学生匹配,学生必须要有匹配,学科不一定。
解法:匈牙利算法计数就ok了
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const double eps=1e-;
const int N=,maxn=,inf=0x3f3f3f3f; bool ok[maxn][maxn],used[maxn];
int vis[maxn],n,m,t; bool match(int x)
{
for(int i=;i<=m;i++)
{
if(!used[i]&&ok[x][i])
{
used[i]=;
if(vis[i]==-||match(vis[i]))
{
vis[i]=x;
return ;
}
}
}
return ;
}
int main()
{
cin>>t;
while(t--){
cin>>n>>m;
bool flag=;
memset(ok,,sizeof(ok));
for(int i=;i<=n;i++)
{
int k,a;
cin>>k;
if(k==)flag=;
while(k--){
cin>>a;
ok[i][a]=;
}
}
memset(vis,-,sizeof(vis));
int i,num=;
for(i=;i<=n;i++)
{
memset(used,,sizeof(used));
if(!match(i))break;
}
if(i==n+)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}
hdu1083二分图匹配模板题的更多相关文章
- HDU - 1054 Strategic Game (二分图匹配模板题)
二分图匹配模板题 #include <bits/stdc++.h> #define FOPI freopen("in.txt", "r", stdi ...
- HDU-2063(二分图匹配模板题)
过山车Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...
- 【二分图裸题】poj1325机器调度
题目大意:有两个机器A和B,A机器有n个模式,B机器有m个模式,两个机器最初在0模式 然后有k个作业,每个作业有三个参数i,a,b i代表作业编号,a和b代表第i作业要么在A机器的a模式下完成[或者] ...
- POJ 3041 Asteroids(二分图模板题)
Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N g ...
- 【HDU 2063】过山车(二分图最大匹配模板题)
题面 RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐.但是,每 ...
- Asteroids(二分图最大匹配模板题)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12323 Accepted: 6716 Description Bess ...
- 51nod 2006 飞行员配对(二分图最大匹配) 裸匈牙利算法 求二分图最大匹配题
题目: 题目已经说了是最大二分匹配题, 查了一下最大二分匹配题有两种解法, 匈牙利算法和网络流. 看了一下觉得匈牙利算法更好理解, 然后我照着小红书模板打了一遍就过了. 匈牙利算法:先试着把没用过的左 ...
- HDU 1083 Courses(二分图匹配模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1083 题意:有p门课和n个学生,每个学生都选了若干门课,每门课都要找一个同学来表演,且一个同学只能表演一门课,判 ...
- Kuhn-Munkres算法。带权二分图匹配模板 (bin神小改版本)
/****************************************************** 二分图最佳匹配 (kuhn munkras 算法 O(m*m*n)). 邻接矩阵形式 . ...
随机推荐
- ArcGIS API for JavaScript FeatureLayer服务属性编辑
首先说一下感想吧,刚入行时感觉深似海,掉到了GIS开发的陨石大坑里了,首先是学了小半年的Flex,用到了ArcGIS API for Flex,接着又是半年的ArcEngine开发,现在终于摸到了一点 ...
- 面试 -- ListView对其指定的子Item进行单独的刷新
1,最近在面试题目的时候突然看到了问题"ListView对其指定的子Item进行单独的刷新",当时感觉一脸懵逼,还是第一次听到这个问题,也就是不能使用adapter.notifyD ...
- windows phone 8.1开发:磁铁|Tile更新
原文出自:http://www.bcmeng.com/tile/ 上一篇给大家分享了toast通知操作的方法,这一篇文章我们就来看windows phone 8.1开发中的磁铁更新.磁铁是window ...
- jquery拖拽插件 tableDnD
http://www.jb51.net/article/39481.htm http://www.poluoluo.com/jzxy/201307/232615.html
- 当在浏览器地址栏里输入URL后会发生什么事情
其实这个很多大神已经说的很多了.但是为了自己更好的理解,在自己所接触的层面上,重新对自己讲解一下.当然,这是站在一个前端开发者的角度上来看问题的. 说说一次HTTP完整事务的过程 输入URL 浏览器从 ...
- Solr6.5在Centos6上的安装与配置 (一)
这篇文章主要是介绍在Centos6上Solr6.5的安装与配置. 一.安装准备及各软件使用版本说明: 1.JDK8,版本jdk1.8.0_121下载地址:jdk-8u121-linux-x64.tar ...
- 高可用系列之Nginx
1.1Keepalived高可用软件 Keepalived起初是专为LVS设计的,专门用来监控LVS集群系统中各个服务节点的状态,后来又加入了VRRP的功能,因此除了配合LVS服务外,也可以作为其他服 ...
- 安全性测试之防范 DDoS 攻击
安全性测试之防范 DDoS 攻击 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:90882 ...
- 自动化测试培训:qtp脚本获取获取汇率数据
poptest(www.poptest.cn)致力于测试开发工程师的培训,以培养能胜任做测试工具开发,完成自动化测试,性能测试,安全性测试等工作能力为目标.自8月份成立2个月内中针对企业在职人员的能力 ...
- DC平衡双向控制解串器 转接IC GM8914:FPD-LINK III转LVTTL芯片
1 概述 GM8914型DC平衡双向控制解串器,其主要功能是实现将2.8Gbps高速串行数据转换成10或12位并行控制信号,并同步输出一路时钟信号:同时低速通道将芯片控制信息调制到高速差分信号上传输给 ...