题目链接:https://vjudge.net/problem/HDU-2444 The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7328    Accepted Submission(s): 3270 Problem Description There are a group o…
题意: 有n个学生,有m对人是认识的,每一对认识的人能分到一间房,问能否把n个学生分成两部分,每部分内的学生互不认识,而两部分之间的学生认识.如果可以分成两部分,就算出房间最多需要多少间,否则就输出No. 思路: 判断是否是二分图,并输出最大匹配数.用'临点填色法'判断,相邻点异色,发现同色则不成立,然后匈牙利算法, 求出个数除2.注:匈牙利算法时间复杂度 '邻接表': O(mn),邻接矩阵: O(n^3). 代码: #include <iostream> #include <stdio…
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6424    Accepted Submission(s): 2880 Problem Description There are a group of students. Some of them may know each o…
//推断是否为二分图:在无向图G中,假设存在奇数回路,则不是二分图.否则是二分图. //推断回路奇偶性:把相邻两点染成黑白两色.假设相邻两点出现颜色同样则存在奇数回路. 也就是非二分图. # include <stdio.h> # include <string.h> # include <algorithm> using namespace std; int vis[210],map[210][210],cott[210]; int c[210]; int flag,…
有n个关系,他们之间某些人相互认识.这样的人有m对.你需要把人分成2组,使得每组人内部之间是相互不认识的.如果可以,就可以安排他们住宿了.安排住宿时,住在一个房间的两个人应该相互认识.最多的能有多少个房间住宿的两个相互认识. 先是要判断是否为二部图,然后求最大匹配. 学习一下模板~ #include<cstdio> #include<cstring> #include<vector> #include<algorithm> using namespace s…
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3565    Accepted Submission(s): 1659 Problem Description There are a group of students. Some of them may know each ot…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2444 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description There are a group of students. Some of them may know each other, while others don't. For ex…
题意: 有一堆的学生关系,要将他们先分成两个组,同组的人都不互不认识,如果不能分2组,输出No.若能,则继续.在两组中挑两个认识的人(每组各1人)到一个双人房.输出需要多少个双人房? 思路: 先判定是否为二分图,可以用黑白着色法(DFS或BFS都行).若是二分图,再进行匹配,用匈牙利算法,注:给的是整个图,没有区分男女,用邻接表比较好. #include <bits/stdc++.h> #define LL long long using namespace std; ; vector<…
本题就是先推断能否够组成二分图,然后用匈牙利算法求出最大匹配. 究竟怎样学习一种新算法呢? 我也不知道什么方法是最佳的了,由于看书本和大牛们写的匈牙利算法具体分析,看了几乎相同两个小时没看懂,最后自己直接看代码,竟然不到半个小时看懂了.然后就能够直接拿来解题啦. 比方topcoder上有这个算法的非常具体的分析.真没看懂. 代码竟然比分析更清晰了?我也不好下结论. 可是我认为基本的思想还是有作用的. 说说我对这个算法的理解吧: 1 假设二分图分为两个集合 U, V,那么从一个集合U出发 2 U的…
http://acm.hdu.edu.cn/showproblem.php?pid=2444 [DFS染色] #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> using namespace std; ; const int maxm=maxn*maxn; struct e…
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9477    Accepted Submission(s): 4165 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2444 Description: There are a gro…
题目链接: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 stu…
Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4669    Accepted Submission(s): 2230 Problem Description Consider a group of N students and P courses. Each student visits zero, one or…
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8418    Accepted Submission(s): 3709 Problem Description There are a group of students. Some of them may know each ot…
Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9100    Accepted Submission(s): 4185 Problem Description the second year of the university somebody started a study on the romant…
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4915    Accepted Submission(s): 2260 Problem Description There are a group of students. Some of them may know each o…
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3775    Accepted Submission(s): 1771 Problem Description There are a group of students. Some of them may know each ot…
//匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; #define MAX 105 #define INF 0x3f3f3f3f int n,m,k; int gp[MAX][MAX]; bool sx[MAX],s…
匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名.匈牙利算法是基于Hall定理中充分性证明的思想,它是部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图最大匹配的算法. -------等等,看得头大?那么请看下面的版本: 通过数代人的努力,你终于赶上了剩男剩女的大潮,假设你是一位光荣的新世纪媒人,在你的手上有N个剩男,M个剩女,每个人都可能对多名异性有好感(-_-||暂时不考虑特殊的性取向),如果一对男女互有好感,那么你就可以把这一对撮合在一起,现在…
匈牙利算法 var i,j,k,l,n,m,v,mm,ans:longint; a:..,..]of longint; p,f:..]of longint; function xyl(x,y:longint):boolean; var i,j,k,l:longint; begin if f[x]=y then exit(false); f[x]:=y; to m do ))or(xyl(p[i],y)))then begin p[i]:=x; exit(true); end; exit(fals…
Strategic Game Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which form a t…
The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22809   Accepted: 10161 Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering p…
染色判读二分图+Hungary匹配 The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1705    Accepted Submission(s): 821 Problem Description There are a group of students. Some of them…
匈牙利 算法 一. 算法简介 匈牙利算法是由匈牙利数学家Edmonds于1965年提出.该算法的核心就是寻找增广路径,它是一种用增广路径求二分图最大匹配的算法. 二分图的定义: 设G=(V,E)是一个无向图,顶点集V可分割为两个互不相交的子集V1,V2,那么称此图G为二分图. 例如,下图就是一个二分图: 二分图的匹配: 二分图中的子图中,每个节点只连一条边,则称该子图是二分图中的一个匹配. 极大匹配: 无法再向二分图中加入边,使得满足匹配条件. 最大匹配: 所有极大匹配中边数最多的一个匹配. 完…
一.关于匈牙利算法 匈牙利算法是由匈牙利数学家Edmonds提出的,用增广路径求二分图最大匹配的算法. 听起来高端,其实说白了就是: 假设不存在单相思(单身狗偷偷抹眼泪),在一个同性恋不合法的国家里(不存在任何歧视#正色),有一些男人和女人,他们互相之间存在一些互相爱恋的关系.而匈牙利算法就是要促成尽量多的男女配对. 如下图: 绿色标注的就是这张图的一个最大二分图匹配. 先提一个下面会提到的名词:增广路:若P是图G中一条连通两个未匹配顶点的路径,并且属于M的边和不属于M的边(即已匹配和待匹配的边…
描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们喜欢的那些牛栏中产奶.上个星期,农夫约翰刚刚收集到了奶牛们的爱好的信息(每头奶牛喜欢在哪些牛栏产奶).一个牛栏只能容纳一头奶牛,当然,一头奶牛只能在一个牛栏中产奶. 给出奶牛们的爱好的信息,计算最大分配方案. 格式 PROGRAM NAME: stall4 INPUT FORMAT: (file s…
二分图最大匹配的匈牙利算法模板题. 由题目易知,需求二分图的最大匹配数,采取匈牙利算法,并采用邻接表来存储边,用邻接矩阵会超时,因为邻接表复杂度O(nm),而邻接矩阵最坏情况下复杂度可达O(n^3). 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> u…
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4091    Accepted Submission(s): 1876 Problem Description There are a group of students. Some of them may know each ot…
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1462    Accepted Submission(s): 716 Problem DescriptionThere are a group of students. Some of them may know each othe…
题目 给定一个图的N个节点和节点之间的M条边,数据保证该图可以构成一个二分图.求该二分图最大匹配. 题目链接:二分图最大匹配     首先通过染色法,将图的N个节点分成两个部分:然后通过匈牙利算法求二分图的最大匹配. 实现 #include<stdio.h> #include<string.h> #include<iostream> #include<string> #include<set> #include<map> #inclu…