题目链接: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. 证明 logX < X 对所有 X > 0 成立

    题目取自:<数据结构与算法分析:C语言描述_原书第二版>——Mark Allen Weiss       练习1.5(a)  证明下列公式: logX < X 对所有 X > ...

  2. 基于Qt实现的截图小程序

    在最近做的行人检测项目中,由于需要训练分类器,而分类器的训练又需要有一个一定长宽的样本.为了方便样本的采集,因此实现了这样的一个截图程序.该程序的主要功能是加载视频到程序中,程序可以对视频进行播放.暂 ...

  3. jvm内存设置

    JVM有很多个内存管理命令,总体而言,分为两类: 1.-X开头的管理命令:这些选项在JDK升级时不会通知修改: 2.-XX开头的管理命令:这些选项不够稳定,所以建议少用. JVM参数的含义: 参数名称 ...

  4. Java基础(44):ArrayList使用详解

    1.什么是ArrayList ArrayList就是传说中的动态数组,用MSDN中的说法,就是Array的复杂版本,它提供了如下一些好处:    a.动态的增加和减少元素    b.实现了IColle ...

  5. C++之路进阶——poj2104(K-th Number)

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 44537   Accepted: 14781 Ca ...

  6. 1.表单中 get与post提交方法的区别?

    get是发送请求HTTP协议通过url参数传递进行接收,而post是实体数据,可以通过表单提交大量信息. get是从服务器上获取数据,post是向服务器传送数据. GET方式提交的数据最多只能有102 ...

  7. ligerui_实际项目_003:form中添加数据,表格(grid)里面显示,最后将表格(grid)里的数据提交到servlet

    实现效果: "Form"中填写数据,向本页"Grid"中添加数据,转换成Json数据提交,计算总和,Grid文本框可编辑,排序 图片效果: 总结: //disp ...

  8. 关于C# winform 快速制作不规则边框的方法

    今天逛博客园突然发现一个帖子写的   快速建立不规则边框的方式 突然发现以前自己用API的方式好傻… 杀鸡焉用牛刀  下边是从网上不断转载的 原帖: 地址:http://www.cnblogs.com ...

  9. 夺命雷公狗ThinkPHP项目之----企业网站1之快速搭建后台

    我们还是老规矩照老方法,将框架里面多余的东西都干掉,然后在index.php里面将框架搭建起来 <?php //定义项目目录 define('APP_PATH','./WEB/'); //开启调 ...

  10. FlexNOC

    arteris公司提供一系列工具,来完成NOC的生成,包括model,netlist,TB,script 生成包括三个阶段: NoC specification Phase:使用FlexArtist ...