Girls and Boys

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3260    Accepted Submission(s): 1405

Problem Description
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.

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, for n subjects.
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
 
题意:求最大独立集
思路:二分图匹配
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<stack>
#include<cstdlib>
#include <vector>
#include<queue>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e3+; int pre[maxn];
bool map[maxn][maxn],used[maxn];
int n; int dfs(int u)
{
for(int v = ;v < n; v++)
{
if(map[u][v] && used[v] == false)
{
used[v] = true;
if(pre[v] == - || dfs(pre[v]))
{
pre[v] = u;
return true;
}
}
}
return false;
}
int main()
{
while(~scanf("%d", &n))
{
memset(map,false,sizeof map);
memset(pre,-,sizeof pre);
for(int i=;i<n;i++)
{
int k,num;
scanf("%d: (%d)",&k,&num);
for(int j=;j<num;j++)
{
int r;
scanf("%d",&r);
map[k][r] = true;
}
}
int sum = ;
for(int i = ; i < n; i++)
{
memset(used,false,sizeof used);
if(dfs(i))
sum++;
}
sum /= ;
printf("%d\n",n-sum);
}
}
 

Girls and Boys-hdu 1068的更多相关文章

  1. Girls and Boys HDU - 1068 二分图匹配(匈牙利)+最大独立集证明

    最大独立集证明参考:https://blog.csdn.net/qq_34564984/article/details/52778763 最大独立集证明: 上图,我们用两个红色的点覆盖了所有边.我们证 ...

  2. HDU 1068 Girls and Boys(最大独立集合 = 顶点数 - 最大匹配数)

    HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream ...

  3. HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. hdu 1068 Girls and Boys (二分匹配)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. hdu 1068 Girls and Boys(匈牙利算法求最大独立集)

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. HDU——1068 Girls and Boys

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. hdu 1068 Girls and Boys (最大独立集)

    Girls and BoysTime Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. (hdu step 6.3.2)Girls and Boys(比赛离开后几个人求不匹配,与邻接矩阵)

    称号: Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  10. Hdu 1068 最小路径覆盖

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. window.open 打开Excel或者Word 无权限问题

    场景:后端C# ashx 前端:js js在对ashx返回结果进行window.open(url)  url为后端保存excel的一个地址 提示:无操作权限 url:为后端处理后,服务器上一个完整的路 ...

  2. Elasticsearch如何安装中文分词插件ik

    elasticsearch-analysis-ik 是一款中文的分词插件,支持自定义词库. 安装步骤: 1.到github网站下载源代码,网站地址为:https://github.com/medcl/ ...

  3. 在MFC对话框中快速集成三维控件

    在MFC的对话框中可以方便的集成AnyCAD三维控件(c++版本),遵循一下几步: 1.在对话框资源中增加一个Static控件,ID为IDC_STATIC_3D,并且把它的Notify属性设置为Tru ...

  4. JSPt的Base标签

    <base href="${pageContext.request.contextPath}/"/> 注意:base标签得到的内容是: /projectName/ 这种 ...

  5. 从零开始的全栈工程师——js篇2.15(offsetLeft)

    元素的属性 Div.attributes 是所有标签属性构成的数据集合 Div.classList 是所有class名构成的数组集合 在classList的原型链上看以看到add()和remove() ...

  6. springMvc 添加定时任务

    1.创建定时类 import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stere ...

  7. 【web】movie review——静态页面训练、css训练

    实现样式要求: image: banner.png: generaloverview.png: background.png: bannerbackground.png: rottenbig.png: ...

  8. hibernate笔记4--qbc查询

    Criteria:是一种完全面向对象的查询方式,Criteria查询也叫做qbc查询(query by Criteria).         查询全部,分页查询,统计查询,条件查询,排序查询,离线查询 ...

  9. Android自定义控件练手——简单的时钟

    首先这应该是一个老生常谈的设计了,但是毕竟身为小白的自己都没动手做过,不动手怎么提高自己呢,所以在这梅林沉船闲暇之际,我就把我的设计流程与思路记录下来.首先来看看效果图吧: 如上图就是一个简单并没有美 ...

  10. 报错:LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏

    参考原文:http://bbs.csdn.net/topics/390121452 项目>属性>配置属性>清单工具>输入和输出>嵌入清单:原来是“是”,改成“否” 如果上 ...