hdu2444】的更多相关文章

题目链接: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…
#include<stdio.h> #include<string.h> #include<queue> using namespace std; #define maxn 210 int map[maxn][maxn],color[maxn]; int vis[maxn],match[maxn],n; int bfs(int u,int n) { int i; queue<int>q; q.push(u); color[u]=; while(!q.empt…
#include <stdio.h> #include <string.h> #define black 1 #define white -1 ]; ]; ][]; int n; ]; int pf,pe; int dfs(int a,int color){ v[a]=color; int i; int sign; ;i<=n;++i){ if(i==a) continue; ){ ) ; }else if(gr[a][i]&&v[i]==color){ ;…
传送门:The Accomodation of Students 题意:有n个学生,m对相互认识的,问能否分成两队,使得每对中没有相互认识的,如果可以求最大匹配,否则输出No. 分析:判断二分图用染色法,然后直接匈牙利算法求最大匹配. #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <iostream> #include <al…
用染色法判断二分图是这样进行的,随便选择一个点, 1.把它染成黑色,然后将它相邻的点染成白色,然后入队列 2.出队列,与这个点相邻的点染成相反的颜色 根据二分图的特性,相同集合内的点颜色是相同的,即 但是如果这个图不是二分图,那么就会这样 把与1相邻的点2,3染成白色,然后入队列,然后2出队列,要把与2相邻的点2,3染成黑色,但是都染过了,所以不用染色 但是3的颜色应该与2相反(如果是二分图的话),可是没有相反,所以就不是二分图 #include <stdio.h> #include <…
There are a group of students. Some of them may know each other, while others don't. For example, A and B know each other, B and C know each other. But this may not imply that A and C know each other. Now you are given all pairs of students who know…
题意: 有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…
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6983    Accepted Submission(s): 3120 Problem Description There are a group of students. Some of them may know each ot…
//推断是否为二分图:在无向图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,…