poj 1466 Girls and Boys(二分匹配之最大独立集)
In the second year of the university somebody started a study on the romantic relations between the students. The relation "romantically involved" is defined between one girl and one boy. For the study reasons it is necessary to find out the maximum set satisfying the condition: there are no two students in the set who have been "romantically involved". The result of the program is the number of students in such a set.
Input
The input contains several data sets in text format. Each data set represents one set of subjects of the study, with the following description: the number of students
the description of each student, in the following format
student_identifier:(number_of_romantic_relations) student_identifier1 student_identifier2 student_identifier3 ...
or
student_identifier:() The student_identifier is an integer number between and n- (n <= ), for n subjects.
Output
For each given data set, the program should write to standard output a line containing the result.
Sample Input
: ()
: ()
: ()
: ()
: ()
: ()
: () : ()
: ()
: ()
Sample Output
Source
题目大意:有n个学生,每个学生都和一些人又关系,现在要你找出最大的人数,使得这些人之间没关系
解题思路:裸的最大独立集,最大独立集=点数-最大匹配数
这里注意因为是两两匹配,所以求出的匹配值要除上个2
优化了几下,时间不断减少
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 506
int n;
int match[N];
int vis[N];
int mp[N][N];
bool dfs(int x){
for(int i=;i<n;i++){
if(!vis[i] && mp[x][i]){
vis[i]=;
if(match[i]==- || dfs(match[i])){
match[i]=x;
return true;
}
}
}
return false;
}
void solve(){
int ans=;
memset(match,-,sizeof(match)); for(int i=;i<n;i++){
memset(vis,,sizeof(vis));
if(dfs(i)){
ans++;
}
}
printf("%d\n",n-ans/);
}
int main()
{ while(scanf("%d",&n)==){
memset(mp,,sizeof(mp));
char s[];
for(int i=;i<n;i++){
scanf("%s",s);
scanf("%s",s);
int num=;
for(int j=;j<strlen(s);j++){
if(s[j]>='' && s[j]<=''){
num=num*+s[j]-'';
}
}
//printf("---%d\n",num);
int x;
for(int j=;j<num;j++){
scanf("%d",&x);
mp[i][x]=mp[x][i]=;
}
}
solve();
}
return ;
}
poj 1466 Girls and Boys(二分匹配之最大独立集)的更多相关文章
- POJ 1466 大学谈恋爱 二分匹配变形 最大独立集
Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 11694 Accepted: 5230 D ...
- poj 1466 Girls and Boys(二分图的最大独立集)
http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submis ...
- POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题
有n个人, 其中有男生和女生,接着有n行,分别给出了每一个人暗恋的对象(不止暗恋一个) 现在要从这n个人中找出一个最大集合,满足这个集合中的任意2个人,都没有暗恋这种关系. 输出集合的元素个数. 刚开 ...
- POJ 1466 Girls and Boys
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- poj 1466 Girls and Boys 二分图的最大匹配
Girls and Boys Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...
- hduoj-----(1068)Girls and Boys(二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1068 Girls and Boys (二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ 1466 Girls and Boys (匈牙利算法 最大独立集)
Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 10912 Accepted: 4887 D ...
- 网络流(最大独立点集):POJ 1466 Girls and Boys
Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ...
- poj 1466 Girls and Boys (最大独立集)
链接:poj 1466 题意:有n个学生,每一个学生都和一些人有关系,如今要你找出最大的人数.使得这些人之间没关系 思路:求最大独立集,最大独立集=点数-最大匹配数 分析:建图时应该是一边是男生的点, ...
随机推荐
- swift菜鸟入门视频教程-04-集合类型
本人自己录制的swift菜鸟入门,欢迎大家拍砖,有什么问题能够在这里留言. 主要内容: 数组(Arrays) 字典(Dictionaries) 集合的可变性(Mutability of Collect ...
- Word03-文档中的截图显示不全
今天写文档时遇到个很蛋疼的问题,在doc文档中复制进去的截图总是显示不全,图片上半部分都被文字遮盖了,折腾半天,最后还是网上找到了答案. 解决方法如下: 将图片所在行的段落行距修改为其它值即可,原来为 ...
- AIX-du
du命令显示用于文件的块的数量.如果指定的File参数实际上是一个目录,就要报告该目录内的所有文件.如果没有提供 File参数,du命令使用当前目录内的文件.如果File参数是一个目录,那么报告的块的 ...
- java listener实现定时任务
使用java ServletContextListener 实现各种简单定时任务. 1. 创建ServletContextListener,在3.0版本的web.xml中不再需要添加listener的 ...
- spring项目中监听器作用-ContextLoaderListener(项目启动时,加载一些东西到缓存中)
作用:在启动Web容器时,自动装配Spring applicationContext.xml的配置信息. 因为它实现了ServletContextListener这个接口,在web.xml配置这个监听 ...
- C语言转义字符相关知识
在C语言里所有的ASCII码都可以用“\”加数字(一般是8进制数字)来表示.而C中定义了一些字母或数字前加"\"来表示常见的那些不能显示的ASCII字符,如\0,\t,\n等,就称 ...
- javascript返回顶部几种代码总结
纯js代码 /** * 回到页面顶部 * @param acceleration 加速度 * @param time 时间间隔 (毫秒) **/ function goTop(acceleration ...
- c++中static的使用
static可以用来修饰变量,包括函数的局部变量,类的成员变量.可以用来修饰函数,包括类的成员函数,普通函数. 今天就只说说static修饰类之外的函数的情况.假设你写了一个head.h,一个a.cp ...
- javascript之事件绑定
曾经写过一篇随笔,attachEvent和addEventListener,跟本文内容有很多相似之处 本文链接:javascript之事件绑定 1.原始写法 <div onclick=" ...
- 无法更新 EntitySet“Ips_Articles”,因为它有一个 DefiningQuery,而 <ModificationFunctionMapping> 元素中没有支持当前操作的 <InsertFunction> 元素。
今天我在使用ef的时候,发现了这样的报错. 无法更新 EntitySet“Ips_Articles”,因为它有一个 DefiningQuery,而 <ModificationFunctionMa ...