(为什么最大独立集的背景都是严打搞对象的( _ _)ノ|壁) 思路:匈牙利算法 没什么可说的-- // by SiriusRen #include <cstdio> #include <cstring> using namespace std; int cases,n,tot,ans,first[555],next[555555],v[555555],fa[555],vis[555]; struct Student{int n;char sex[2],music[105],spor…
Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23963   Accepted: 12989 Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K a…
http://poj.org/problem?id=3041 #include <cstdio> #include <cstring> #include <vector> using namespace std; int e[1004][1004]; bool vis[1004]; vector <int > G[1004]; int n,m; int dfs(int s){ vis[s]=true; if(s==n*2+1){//printf("…
http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19419   Accepted: 7642 Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is…
题意:n个学生,给你每个学生浪漫的学生学号(男女之间浪漫),问你找出一个最大的集合保证集合内的任意两个学生之间没有相互浪漫关系,输出最大集合的人数. 注意:这里的浪漫边是双向的,如果1对2浪漫, 那么2对1也浪漫,题意好像没说清楚, 但我测了一下,是双向边. 思路:最大独立集和最小点覆盖集是互补的,所以 最大独立集 == 总人数n - 最小点覆盖集, 如果题目给你的是二分图那么直接二分匹配一下即可,但这题不是二分图,我们抓住双向边,那么我们进行拆点, 做一次匹配,求出来的匹配数是(左边男生匹配右…
emmmmm 让你敲个匈牙利 #include<cstdio> #include<algorithm> #include<cstring> #define N 510 using namespace std; int adj[N][N],n,k,vis[N],bf[N],cnt; int find(int x) { ;i<=n;i++) if (adj[x][i] && !vis[i]) { vis[i]=; if (!bf[i] || find(…
#include<stdio.h> #include<string.h>//这个分开后男的站在一边女的站在一边,不肯能有les或者gay.最大独立集=n-最大匹配数 #define  N  510 int map[N][N],n,mark[N],link[N]; int find(int u) {  int i;  for(i=0;i<=n;i++)  if(!mark[i]&&map[u][i]) {     mark[i]=1;     if(link[i…
题目链接: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…
链接:poj 1466 题意:有n个学生,每一个学生都和一些人有关系,如今要你找出最大的人数.使得这些人之间没关系 思路:求最大独立集,最大独立集=点数-最大匹配数 分析:建图时应该是一边是男生的点,一边是女生的点连边.可是题目中没说性别的问题.仅仅能将每一个点拆成两个点.一个当作是男的点,一个当作是女的点了,然后连边.因为关系是相互的.这样就造成了边的反复.也就是边集是刚才的二倍,从而导致了最大匹配变成了原本的二倍.因此,此时最大独立集=点数-最大匹配数/2. #include<stdio.h…
传送门:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (…
http://poj.org/problem?id=3041 在n*n的网格中有K颗小行星,小行星i的位置是(Ri,Ci),现在有一个强有力的武器能够用一发光速将一整行或一整列的小行星轰为灰烬,想要利用这个武器摧毁所有的小行星最少需要几发光束. 主要是构图,将每一行当成一个点,构成集合1,每一列也当成一个点,构成集合2,每一个障碍物的位置坐标将集合1和集合2的点连接起来,也就是将每一个障碍物作为连接节点的边,这样可以得出本题是一个最小点覆盖的问题==二分图的最大匹配. 就可以通过匈牙利算法求解.…
题目传送门 /* 题意:*的点占据后能顺带占据四个方向的一个*,问最少要占据多少个 匈牙利算法:按坐标奇偶性把*分为两个集合,那么除了匹配的其中一方是顺带占据外,其他都要占据 */ #include <cstdio> #include <algorithm> #include <cstring> #include <vector> using namespace std; ; const int INF = 0x3f3f3f3f; ][]; ][]; boo…
题目传送门 /* 题意:每次能消灭一行或一列的障碍物,要求最少的次数. 匈牙利算法:把行和列看做两个集合,当有障碍物连接时连一条边,问题转换为最小点覆盖数==二分图最大匹配数 趣味入门:http://blog.csdn.net/dark_scope/article/details/8880547 */ #include <cstdio> #include <algorithm> #include <cstring> #include <vector> usi…
题目网址:  http://poj.org/problem?id=3020 题意: 用椭圆形去覆盖给出所有环(即图上的小圆点),有两种类型的椭圆形,左右朝向和上下朝向的,一个椭圆形最多可以覆盖相邻的两个小圆点.   思路: 将每个小圆点看作是一个顶点,因为一个椭圆只能覆盖两个小圆点,我们就可以把这个图看成一个二分图.将相邻的两个点,一个看作是X集合内顶点,另一个看成是Y集合内顶点.但要注意的是一个顶点可能不止和一个顶点想连(如上图情况),所以我们要把上述情况看作是一个无向图,而不是有向图.因为是…
嗯... 题目链接:http://poj.org/problem?id=3041 这道题的思想比较奇特: 把x坐标.y坐标分别看成是二分图两边的点,如果(x,y)上有行星,则将(x,y)之间连一条边,而我们要做的就是要找尽量少的点把所有的边覆盖,即为最小点覆盖问题,根据König定理:最小覆盖点数=最大匹配数,所以就可以用匈牙利算法求最大匹配了. AC代码: #include<cstdio> #include<cstring> #include<iostream> us…
The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20874   Accepted: 9421 Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering pr…
System Engineer Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 507   Accepted: 217 Description Bob is a skilled system engineer. He is always facing challenging problems, and now he must solve a new one. He has to handle a set of server…
题目链接:https://cn.vjudge.net/problem/POJ-1904 自己一开始的想法,打算用匈牙利算法实现,找二分图的最大匹配.但是打了打发现,不太好实现.原因如下:匈牙利算法是不停的找增广路.如果这个题用匈牙利算法实现的时候,就是这个地方: bool Find(int t) { ; i<=m; i++) { ) { Exit[i]=; ||Find(net[i])) { net[i]=t; return true; } } } } ,这个是找到合法的就返回,无法把所有的情况…
题意: P门课程,N个学生.给出每门课程的选课学生,求是否可以给每门课程选出一个课代表.课代表必须是选了该课的学生且每个学生只能当一门课程的. 题解: 匈牙利算法的入门题. #include <iostream> #include <cstring> #include <cstdio> #include <vector> using namespace std; ; int t; int k, s; int flag; int p, n; int vis[m…
Machine Schedule As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type o…
Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12976   Accepted: 5529 Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduli…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=137 http://poj.org/problem?id=1466 题目大意: n个学生,他们中有的有关系,有的没有关系,求最多可以取出几个人,使得他们之间没有关系. 思路: 复制别人的..... 最大独立集问题:在N个点的图G中选出m个点,使这m个点两两之间没有边.求m最大值.如果图G满足二分图条件,则可以用二分图匹配来做.最大独立集点数 = N - 最大匹配数/2,然后就是…
Girls and Boys Time Limit: 5000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ID: 1466 64-bit integer IO format: %lld      Java class name: Main In the second year of the university somebody started a study on the romantic(浪漫的)…
Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Description In the second year of the university somebody started a study on the romantic relations between the students. The relation "romantically involved&q…
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…
定义 如果一个图\((E,V)\)的顶点集\(E\)能够被能够被分成两个不相交的集合\(X,Y\),且每一条边都恰连接\(X,Y\)中的各一个顶点,那么这个图就是一个二分图. 容易得知,它就是不含有奇数环的图(这个等价定义有时候很重要). 一个匹配是一个边的集合,其中任意两条边都没有公共顶点.顾名思义可以得到一个图的最大匹配的定义.特别地,如果一个图的某个匹配中,所有顶点都是匹配点,那么它是一个完美匹配. 由完美匹配和最大匹配这两个定义我们可以得到两类问题: 有没有可能使得所有顶点都被匹配? 一…
/** 题目:poj3041 Asteroids 链接:http://poj.org/problem?id=3041 题意:给定n*n的矩阵,'X'表示障碍物,'.'表示空格;你有一把枪,每一发子弹可以消除一行或者一列的障碍物, 问最少需要多少颗子弹可以清空障碍物? 思路:最小点集覆盖问题,等价于最大匹配.把所有的行看做二分图的左边的节点,所有的列看做二分图右边的节点. 如果f[i][j]==true;那么第i行与第j列有关系,连一条边.对这个二分图求最大匹配即可. 采用匈牙利算法. 匈牙利算法…
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…
网格图黑白染色,然后能互相攻击到的点之间连边,跑匈牙利算法最大匹配,答案是好点个数-最大匹配(最大独立集) 注意pao的时候只从一种颜色的格子统计即可 #include<iostream> #include<cstdio> using namespace std; const int N=205,dx[]={2,2,-2,-2,-1,-1,1,1},dy[]={-1,1,-1,1,-2,2,-2,2}; int n,m,sum,h[N*N],cnt,id[N][N],a[N][N]…
(点击此处查看原题) 匈牙利算法简介 个人认为这个算法是一种贪心+暴力的算法,对于二分图的两部X和Y,记x为X部一点,y为Y部一点,我们枚举X的每个点x,如果Y部存在匹配的点y并且y没有被其他的x匹配,那就直接匹配:如果Y中已经没有可以和x匹配的点(包括可以匹配的点已经被其他的x匹配),那就让已经匹配的y的原配x'寻找其他可以匹配的y’,并将y和x匹配,最后,统计出匹配的对数 (详细了解的话,可以看看这位的博客:https://blog.csdn.net/sunny_hun/article/de…