POJ 1469:COURSES
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 19458 | Accepted: 7658 |
Description
- 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
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
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
选课。给了每一门课有那些学生选。要问的是在给定的关系的情况下,能不能求出一个学生集合,这个集合里面能够满足这样的关系:
1.每门课都能派出一个学生代表。
2.每个学生都代表了一门课。
不能更匈牙利了。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int grid[305][305];
int link[305];
int visit[305];
int n,k,V1,V2;
int result; bool dfs(int x)
{
int i;
for(i=1;i<=V2;i++)
{
if(grid[x][i]==1&&visit[i]==0)
{
visit[i]=1;
if(link[i]==-1||dfs(link[i]))
{
link[i]=x;
return true;
}
}
}
return false;
} bool Magyarors()
{
int i; result=0;
memset(link,-1,sizeof(link));//!!这里不能是0 for(i=1;i<=V1;i++)
{
memset(visit,0,sizeof(visit));
if(!dfs(i))
{
return false;
}
}
return true;
} int main()
{
int Test,i,j,num,temp;
cin>>Test; while(Test--)
{
memset(grid,0,sizeof(grid));
cin>>V1>>V2; for(i=1;i<=V1;i++)
{
scanf("%d",&num);
for(j=1;j<=num;j++)
{
scanf("%d",&temp);
grid[i][temp]=1;
}
}
if(V1>V2)
{
cout<<"NO"<<endl;
}
else
{
if(Magyarors())
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 1469:COURSES的更多相关文章
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- poj——2239 Selecting Courses
poj——2239 Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10656 A ...
- POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)
http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- 二分图匹配 最大匹配数+最大点覆盖 POJ 1469+POJ 3041
最大匹配数就等于最大点覆盖,因为在图里面,凡是要覆盖的点必定是连通的,而最大匹配之后,若还有点没有覆盖到,则必定有新的匹配,与最大匹配数矛盾,如果去掉一些匹配,则必定有点没有覆盖到. POJ 1469 ...
- poj 1469 COURSES(匈牙利算法模板)
http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- HDU - 1083 Courses /POJ - 1469
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 http://poj.org/problem?id=1469 题意:给你P个课程,并且给出每个课 ...
- poj 1469 COURSES 解题报告
题目链接:http://poj.org/problem?id=1469 题目意思:有 N 个人,P个课程,每一个课程有一些学生参加(0个.1个或多个参加).问 能否使得 P 个课程 恰好与 P 个学生 ...
- POJ 1469 COURSES 二分图最大匹配 二分图
http://poj.org/problem?id=1469 这道题我绝壁写过但是以前没有mark过二分图最大匹配的代码mark一下. 匈牙利 O(mn) #include<cstdio> ...
随机推荐
- 旧iPhone遭禁,会让苹果产业链迎来新转机吗?
过去几个月,苹果的日子并不好过,先是新iPhone定价过高导致销售疲软,股价连续下跌,万亿市值失守,被微软和亚马逊超越:手机销量上则被华为赶超,整个iPhone产业链都有点儿"哀鸿遍野&qu ...
- springCloud 之 Eureka服务治理机制及代码运行
服务提供者 服务注册: 服务提供者在启动的时候通过发送Rest请求的方式将自己注册到Eureka Server上,同时带上了自身服务的一些元数据信息.Eureka Server在收到这个请求后,将元数 ...
- JS 判断是否为安卓或IOS系统
其实很简单,代码如下<script type="text/javascript"> var device = navigator.userAgent; || devic ...
- 我的Grunt之旅-初识gruntfile文件
时间:2018-03-06 18:23 事件:配置 gruntfile.js文件 首先,回忆一下之前的点,grunt项目下面必须有两个文件 ,第一个 package.json ,第二个 Gru ...
- 022、MySQL字符串的拼接
SELECT CONCAT('曾经沧海难为水-','-除却巫山不是云') #字符串拼接 SELECT CONCAT('AB','CD','EF'); #ABCDEF #字符串拼接 SELECT CON ...
- CentOS7 防火墙设置
CentOS7 防火墙命令 最近在公司服务器上安装了oracle12c数据库,在用数据库客户端连接的时候,连接不了.最后查找资料的原因是因为oracle的服务端口未开放. 首先还是还是输入以往的开启某 ...
- java代码静态分析工具
需求:有些基础类型的遍历,值希望它被赋予指定的几个值,赋予其他值能够别编译器(IDEA/eclipse)提醒 Android studu结合自己的插件,引入 <!-- https://mvnre ...
- Django(六)实战2:向数据库添加,删除数据、重定向写法、重定向简写
一.向数据库添加图书数据 [上接]https://blog.csdn.net/u010132177/article/details/103831173 1)首先开启mysql服务,并运行项目 启动my ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-zoom-in
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- DStream-04 Window函数的原理和源码
DStream 中 window 函数有两种,一种是普通 WindowedDStream,另外一种是针对 window聚合 优化的 ReducedWindowedDStream. Demo objec ...