HDU1068 二分匹配 独立集
前边和后边性别不同!!!不然NP了
Girls and Boys
Problem Description
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.
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
2
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<string>
#include<memory.h>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
int Map[][];
int used[],linke[];
int s,t,n;
int _S(){
char c=getchar();
while(c>''||c<'') c=getchar();
int num=;
while(c<=''&&c>='') {
num=num*+c-'';
c=getchar();
}
return num;
}
bool _find(int v)
{
for(int i=;i<=n;i++){
if(Map[v][i]&&!used[i])
{
used[i]=;
if((linke[i]==-)||_find(linke[i])){
linke[i]=v;
return true;
}
}
}
return false;
}
int main()
{
int m,i,j,ans=,tmp;
while(~scanf("%d",&n)){
ans=;
memset(linke,-,sizeof(linke));
memset(Map,,sizeof(Map));
for(int d=;d<=n;d++){
s=_S();
tmp=_S();
for(i=;i<=tmp;i++){
t=_S();
Map[s+][t+]=;
}
} for(i=;i<=n;i++){
memset(used,,sizeof(used));
if(_find(i)) ans++;
} cout<<n-ans/<<endl;
}
return ;
}
HDU1068 二分匹配 独立集的更多相关文章
- hdu1068 Girls and Boys 二分匹配
题目链接: 二分匹配的应用 求最大独立集 最大独立集等于=顶点数-匹配数 本体中由于男孩和女孩的学号是不分开的,所以匹配数应是求得的匹配数/2 代码: #include<iostream> ...
- POJ 1466 Girls and Boys 黑白染色 + 二分匹配 (最大独立集) 好题
有n个人, 其中有男生和女生,接着有n行,分别给出了每一个人暗恋的对象(不止暗恋一个) 现在要从这n个人中找出一个最大集合,满足这个集合中的任意2个人,都没有暗恋这种关系. 输出集合的元素个数. 刚开 ...
- HDU 1068 Girls and Boys 二分图最大独立集(最大二分匹配)
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树
二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- [kuangbin带你飞]专题十 匹配问题 二分匹配部分
刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...
- BZOJ 1189 二分匹配 || 最大流
1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1155 Solved: 420[Submi ...
- Kingdom of Obsession---hdu5943(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
随机推荐
- ActiveMQ持久化消息的三种方式
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt362 本文只介绍三种方式,分别是持久化为文件,MYSql,Oracle.下面 ...
- 【小白成长撸】--链栈(C语言版)
// 链栈.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdio.h> #include <st ...
- oracle 数据的导入导出
一.数据导出 1.为输出路径建立一个数据库的directory对象. create or replace directory dumpdir as 'd:\'; 可以通过:select * from ...
- window.requestAnimationFrame() ,做逐帧动画,你值得拥有
window.requestAnimationFrame() 方法告诉浏览器您希望执行动画,并请求浏览器调用指定的函数在下一次重绘之前更新动画.该方法使用一个回调函数作为参数,这个回调函数会在浏览器重 ...
- Python虚拟环境virtualenv
用意 virtualenv可以搭建虚拟且独立的python运行环境, 使得单个项目的运行环境与其它项目独立起来. 安装 virtualenv本质上是个python包, 使用pip安装 pip inst ...
- 测试与发布(Alpha版本)
[Alpha阶段]测试报告 1.测试找出的BUG (1).这种情况刷新就好 (2).文件必须10个才行,多余10个的部分不会进入查重的部分,少于会出错: (3).文件保存在d:\files,由于有些原 ...
- mysql外键设置选项
. cascade方式 在父表上update/delete记录时,同步update/delete掉子表的匹配记录 . set null方式 在父表上update/delete记录时,将子表上匹配记录的 ...
- 201521123117 《Java程序设计》第6周学习总结
1. 本周学习总结 2. 书面作业 Q1.clone方法 1.Object对象中的clone方法是被protected修饰,在自定义的类中覆盖clone方法时需要注意什么? 答:在自定义的类中覆盖cl ...
- ubuntu下php不能显示中文的问题的解决过程。
在阿里的ECS上的ubuntu平台上成功的安装了apache2和php5与mysql,并进行了测试. 如图所示:
- HTML 自动、手动切换轮播 from:金水
.自动.手动切换轮播 body代码: <div id="tuijian"> <div class="pages" id="p1&qu ...