题目链接:http://poj.org/problem?id=1466

Girls and Boys
Time Limit: 5000MS   Memory Limit: 10000K
Total Submissions: 12026   Accepted: 5355

Description

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:(0)

The student_identifier is an integer number between 0 and n-1 (n <=500 ), for n subjects.

Output

For each given data set, the program should write to standard output a line containing the result.

Sample Input

7
0: (3) 4 5 6
1: (2) 4 6
2: (0)
3: (0)
4: (2) 0 1
5: (1) 0
6: (2) 0 1
3
0: (2) 1 2
1: (1) 0
2: (1) 0

Sample Output

5
2

Source

 
题意:
就是有n个人,每个人与其他的某几个人有关系,这个关系且称为浪漫关系,然后最后求一个最大的集合,使得集合中所有的人两两之间都不存在浪漫关系。
分析:
1、最大独立集 = 顶点数 - 最大匹配数
2、匈牙利算法
3、这里的男女性别没有给出,匹配关系放大一倍,那么实际的匹配数就是/2了。
 
#include <stdio.h>
#include <string.h> #define MAX 505 int n;
bool maps[MAX][MAX];
bool use[MAX];
int match[MAX]; bool DFS(int stu)
{
int num = ;
for(int i=; i<n; i++)
{
if(!use[i]&&maps[stu][i])
{
use[i] = true;
if(match[i]==-||DFS(match[i]))
{
match[i] = stu;
return true;
}
}
}
return false;
} int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(match,-,sizeof(match));
memset(maps,false,sizeof(maps));
for(int i=; i<n; i++)
{
int u,num;
scanf("%d: (%d)",&u,&num);
for(int i=; i<num; i++)
{
int v;
scanf("%d",&v);
maps[u][v] = true;
}
}
int num = ;
for(int i=; i<n; i++)
{
memset(use,false,sizeof(use));
if(DFS(i)) num++;
}
printf("%d\n",n-num/);
}
return ;
}

Poj(1466),最大独立集,匈牙利算法的更多相关文章

  1. POJ 2771 最大独立集 匈牙利算法

    (为什么最大独立集的背景都是严打搞对象的( _ _)ノ|壁) 思路:匈牙利算法 没什么可说的-- // by SiriusRen #include <cstdio> #include &l ...

  2. POJ 3041.Asteroids-Hungary(匈牙利算法)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23963   Accepted: 12989 Descr ...

  3. POJ 3041 Asteroids 匈牙利算法,最大流解法,行列为点 难度:1

    http://poj.org/problem?id=3041 #include <cstdio> #include <cstring> #include <vector& ...

  4. poj 1469 COURSES(匈牙利算法模板)

    http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

  5. POJ 1466 最大独立集入门

    题意:n个学生,给你每个学生浪漫的学生学号(男女之间浪漫),问你找出一个最大的集合保证集合内的任意两个学生之间没有相互浪漫关系,输出最大集合的人数. 注意:这里的浪漫边是双向的,如果1对2浪漫, 那么 ...

  6. POJ 3041 Asteroids | 匈牙利算法模板

    emmmmm 让你敲个匈牙利 #include<cstdio> #include<algorithm> #include<cstring> #define N 51 ...

  7. poj 1466 最大独立集

    #include<stdio.h> #include<string.h>//这个分开后男的站在一边女的站在一边,不肯能有les或者gay.最大独立集=n-最大匹配数 #defi ...

  8. poj 1466 Girls and Boys (最大独立集)

    链接:poj 1466 题意:有n个学生,每一个学生都和一些人有关系,如今要你找出最大的人数.使得这些人之间没关系 思路:求最大独立集,最大独立集=点数-最大匹配数 分析:建图时应该是一边是男生的点, ...

  9. POJ:3041-Asteroids(匈牙利算法模板)

    传送门:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Description Bes ...

随机推荐

  1. Lintcode: Minimum Adjustment Cost

    Given an integer array, adjust each integers so that the difference of every adjcent integers are no ...

  2. UVALive 7148 LRIP【树分治+线段树】

    题意就是要求一棵树上的最长不下降序列,同时不下降序列的最小值与最大值不超过D. 做法是树分治+线段树,假设树根是x,y是其当前需要处理的子树,对于子树y,需要处理出两个数组MN,MX,MN[i]表示以 ...

  3. Android -- 自定义View小Demo,绘制钟表时间(一)

    1,昨天刚看了hongyang大神推荐的自定义时钟效果(传动门:http://www.jianshu.com/users/a45d19d680af/),效果还是不错的,自己又在github上找了找,发 ...

  4. 利用API 建立Dependent Value Set

    . 建立SET fnd_flex_val_api.create_valueset_independent(v_set_name ,v_description ,v_security ,v_enable ...

  5. 用VS2010编C#程序扫盲

    0. Properties文件夹 定义你程序集的属性 项目属性文件夹 一般只有一个 AssemblyInfo.cs 类文件,用于保存程序集的信息,如名称,版本等,这些信息一般与项目属性面板中的数据对应 ...

  6. 【RoR win32】安装RoR

    在配置好ruby的win 7 命令行下运行, gem install rails 安装成功之后会收到提示,下面就可以用rails建立项目了. 为了提高“rails new”时“bundle insta ...

  7. 【NOIP模拟赛】正方形大阵

    正方形大阵 [问题描述]   [输入格式]   第一行一个正整数n代表询问次数. 接下来n行每行一个不超过八位的小数k代表一组询问. [输出格式]   输出共n行,代表每次询问的答案:如果有无数个交点 ...

  8. SQL的主键和外键约束(转)

    SQL的主键和外键的作用: 外键取值规则:空值或参照的主键值. (1)插入非空值时,如果主键表中没有这个值,则不能插入. (2)更新时,不能改为主键表中没有的值. (3)删除主键表记录时,你可以在建外 ...

  9. Controller 接口控制器详解

    Controller 控制器,是 MVC 中的部分 C,为什么是部分呢?因为此处的控制器主要负责功能处理部分:1.收集.验证请求参数并绑定到命令对象:2.将命令对象交给业务对象,由业务对象处理并返回模 ...

  10. FastJson之有道翻译

    在AndroidMainifast.xml中加入相应的访问权限 <uses-permission android:name="android.permission.INTERNET&q ...