![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
二分图
Are_you_ready
这个作者很懒,什么都没留下…
展开
-
D - Swap Free(二分图最大独立集)
题目:https://vjudge.z180.cn/problem/Gym-102423D题意:有一个单词的集合,然后某个单词经过俩个字母的互换能够变成令一个单词,那么他俩就不能在一个集合,求这个集合的最大数量题解:如果A单词经过俩字母互换可以变成B单词,然后A单词经过俩字母互换也可以变成C单词,那么B单词一定不能经过字母互换变成C单词,符合染色法,可以用二分图,,,其实这个题就是求二分图的最大独立集。最大独立集:任意俩点之间都没有边相连的点集称为独立集,那么最大独立就是点数最多:最大团:任意俩点之原创 2021-01-22 11:15:40 · 211 阅读 · 0 评论 -
A - Wrestling Match HDU - 5971 (染色+二分图)
https://vjudge.net/contest/412211#problem/A#include <iostream>#include <cmath>#include <cstdio>#include <queue>#include <vector>#include <cstring>using namespace std;const int M = 10009, N = 1009;bool vis[N];in原创 2020-12-09 15:22:55 · 141 阅读 · 0 评论 -
奔小康赚大钱 HDU - 2255(带权二分图 模板)
https://vjudge.net/problem/HDU-2255题意:n个村民重新分配n间房子,接下来n行表示,第i个村民对第j个房子出的价格,问怎样才能使村里的机构获得最大收入。思路:KM算法模板。KM算法详解:https://www.cnblogs.com/fzl194/p/8848061.htmlhttps://www.cnblogs.com/fzl194/p/8834847.html#include<iostream>#include<cstdio>转载 2020-08-24 15:05:45 · 100 阅读 · 0 评论 -
Cat VS Dog HDU - 3829 (二分图,找二分图)
题目入口题意:有p个小朋友参观动物园,动物园里面有两种动物,分别为猫和狗。规定一个小朋友喜欢猫就讨厌狗,喜欢狗就讨厌猫。现在管理员要移走一些动物,当然,移走也是有条件的。比如一个小朋友喜欢猫3,讨厌狗4.那么移走了狗4,这个小朋友就会非常开心。同样,如果移走猫3或者没有移走狗4,小朋友就会很不高兴。现在问怎么样才能使开心的小朋友的人数最多。思路:先想在狗和猫之间建边,但是不可行,样例就给了提醒,两个小朋友喜欢和讨厌的一模一样,则这么求解会有遗漏。所以可以尝试在小朋友之间进行建边,如果两个小朋友之间存转载 2020-08-24 11:32:13 · 151 阅读 · 0 评论 -
Treasure Exploration POJ - 2594(二分图最小路径的覆盖 路径可相交(A-B,B-C==A-C))
题目入口 https://vjudge.net/problem/POJ-2594讲解博客 https://www.cnblogs.com/ka200812/archive/2011/07/31/2122641.html给定一个有向无环图,求用最少的可以相交的简单路径去覆盖所有结点。最小路径覆盖是用最少的不相交的简单路径去覆盖有向无环图的所有结点,而这里是可以相交。所有需要简单地变形一下,用floyed去传递闭包,增加一些边使得两条相交路径的所有结点可以用两条不相交路径的所有结点表示。即如果有边(i原创 2020-08-24 10:47:38 · 91 阅读 · 0 评论 -
Air Raid HDU - 1151(有向无环图&& 最小路径覆盖&&最大匹配数)
传送门:添加链接描述题目大意:有一个城镇有n个路口和m条路,分配伞兵去守这些路口,每个伞兵只能沿着路的方向走,问最少需要多少伞兵可以把所有路巡查一遍。思路:有向无环图求最小路径覆盖问题。有向无环图的最小路径覆盖=所有顶点-最大匹配数。#include<iostream>#include<algorithm>#include<cstdio>#include<string>#include<cstring>#include<que原创 2020-08-22 17:41:58 · 126 阅读 · 0 评论 -
Antenna Placement POJ - 3020(二分图最大匹配&&最小边(路径)覆盖&&地图抽象&&vetcor)
题目连接最小边覆盖===涉及到的点数data 减去 最大匹配数给定一个nm的字符矩阵,‘o’表示空地,’‘表示城市。现要在城市建立基站,使得所有的城市都有信号。每个基站只能覆盖两个相邻点(包括基站建立点在内)。求最少的基站数。将城市作为点集,相邻城市连边,如此构建一个图。这个图可以看作一个二分图,这样,这就是一个最小边覆盖问题。根据结论“最小边覆盖=顶点数-最大匹配”,我们只要求出二分图的最大匹配即可。根据字符矩阵得到图,然后我们可以通过染色去确定二分图的X集和Y集。也可以将所有点看作X’集,所有点转载 2020-08-22 16:55:24 · 116 阅读 · 0 评论 -
Strategic Game HDU - 1054(二分图 最小顶点覆盖=最大匹配数 vector写法)
题意:一个无向树,n个点,问最少多少个点可以使每个边都与这些点相连。解:1.最大匹配数等于最小顶点覆盖数。画一个图思考一下就知道了。2.套用匈牙利算法模板。3.注意无向图最后匹配数需除2。因为是双边,调试一下就知道了。Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. N原创 2020-08-22 11:32:26 · 122 阅读 · 0 评论 -
Oil Skimming HDU - 4185 (二分图 当图中的俩个点有关系的时候,进行抽象)
Oil Skimming HDU - 4185题目:https://vjudge.net/problem/HDU-4185Thanks to a certain “green” resources company, there is a new profitable industry of oil skimming. There are large slicks of crude oil floating in the Gulf of Mexico just waiting to be scooped原创 2020-08-21 16:39:04 · 117 阅读 · 0 评论 -
Rain on your Parade HDU - 2389(二分图 Hopcroft-Carp的算法模板:比匈牙利快)
You’re giving a party in the garden of your villa by the sea. The party is a huge success, and everyone is here. It’s a warm, sunny evening, and a soothing wind sends fresh, salty air from the sea. The evening is progressing just as you had imagined. It co转载 2020-08-21 11:09:08 · 186 阅读 · 0 评论 -
Swap HDU - 2819(二分图 交换行与列,把行和列看成u和v)
Given an NN matrix with each entry equal to 0 or 1. You can swap any two rows or any two columns. Can you find a way to make all the diagonal entries equal to 1?InputThere are several test cases in the input. The first line of each test case is an intege原创 2020-08-21 10:28:25 · 103 阅读 · 0 评论 -
J. Architect of Your Own Fortune (二分图最大匹配 u和v俩队完全独立)
Vasya is a schoolboy who rides a trolley bus and then a bus to get to school. He’salways very happy to get a “lucky ticket,” which means the total of the first threedigits in the ticket number equals the total of the last three digits. However, Vasya has原创 2020-08-20 21:06:55 · 153 阅读 · 0 评论 -
The Accomodation of Students HDU - 2444 (判断是否是二分图+无权二分图最大匹配)
题意: 有n个人,m对人相互认识; 问能否分成两个组,组内任意两个人之间不认识; 若不能,则输出 No; 若能,则相互认识的两个人一间房,求最多需要几间房;给出一些学生的认识情况,比如A和B认识,B和C认识,但是A和C不一定认识。现在问能否将这些学生分成两个组,并且每组中的学生互相不认识,如果能分,求出最大能匹配的学生对数。There are a group of students. Some of them may know each other, while others don’t. For ex原创 2020-08-20 11:20:38 · 112 阅读 · 0 评论