【HDOJ】2444 The Accomodation of Students
图论的题目。着色原理+二分图匹配。
#include <cstdio>
#include <cstring> #define MAXN 205 char map[MAXN][MAXN];
int link[MAXN];
int color[MAXN];
bool visit[MAXN];
int n, m; bool dfs(int v, int col) {
int i; for (i=; i<=n; ++i) {
if (map[i][v]) {
if (color[i] == col)
return false;
else if (color[i] == ) {
color[i] = -col;
if (dfs(i, -col) == false)
return false;
}
}
}
return true;
} bool find(int v) {
int i; for (i=; i<=n; ++i) {
if (!visit[i] && map[i][v]) {
visit[i] = true;
if (link[i]== || find(link[i])) {
link[i] = v;
return true;
}
}
}
return false;
} int main() {
int ans;
int i, j; while (scanf("%d%d", &n, &m) != EOF) {
memset(map, , sizeof(map));
memset(link, , sizeof(link));
memset(color, , sizeof(color));
while (m--) {
scanf("%d %d", &i, &j);
map[i][j] = map[j][i] = ;
}
color[] = ;
if (dfs(, ) == false) {
printf("No\n");
continue;
}
for (ans=, i=; i<=n; ++i) {
memset(visit, false, sizeof(visit));
if (find(i))
++ans;
}
printf("%d\n", ans/);
} return ;
}
【HDOJ】2444 The Accomodation of Students的更多相关文章
- hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)
http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS Me ...
- HDU 2444 The Accomodation of Students 二分图判定+最大匹配
题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...
- HDOJ 2444 The Accomodation of Students
染色判读二分图+Hungary匹配 The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limi ...
- hdu 2444 The Accomodation of Students 判断二分图+二分匹配
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 2444 The Accomodation of Students(判断二分图+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU——2444 The Accomodation of Students
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 2444 The Accomodation of Students (判断二分图,最大匹配)
The Accomodation of StudentsTime Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- hdu 2444 The Accomodation of Students(二分匹配 匈牙利算法 邻接表实现)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 2444 The Accomodation of Students 【二分图匹配】
There are a group of students. Some of them may know each other, while others don't. For example, A ...
随机推荐
- Qt 学习之路 :文件
文件操作是应用程序必不可少的部分.Qt 作为一个通用开发库,提供了跨平台的文件操作能力.从本章开始,我们来了解下 Qt 的文件以及输入输出的功能,也就是 I/O 系统. Qt 通过QIODevice提 ...
- c++中返回对象与返回引用的区别
这几天在做用C++做课程设计,对其返回对象的实现感到迷惑. 通过对汇编代码的分析,可以清楚的看到,直接返回引用和返回对象的区别到底是什么. 分析的程序如下 #include<cstdio> ...
- mac下的secureCRT破解方案
Mac下面的SecureCRT(附破解方案) 更新到最新的7.3.2 转自 http://bbs.weiphone.com/read-htm-tid-6939481.html 继续更新到7.3.2的破 ...
- 11.3 afternoon
迭代40 #include<cstdio> #include<cstring> using namespace std; int n,sum,falg; ],c[]; void ...
- WPF中的资源简介、DynamicResource与StaticResource的区别(转)
什么叫WPF的资源(Resource)?资源是保存在可执行文件中的一种不可执行数据.在WPF的资源中,几乎可以包含图像.字符串等所有的任意CLR对象,只要对象有一个默认的构造函数和独立的属性. 也就是 ...
- 为什么选择Typescript
上一节,我简单介绍了Typescript,并将Typescript和JavaScript进行了对比,有些网友提出了一些疑问,可能有些网友对于这个Typescript还不是特别的熟悉,这节,我做一些演示 ...
- 绘图quartz之阴影
//设置矩形的阴影 并在后边加一个圆 不带阴影 步骤: CGContextRef context = UIGraphicsGetCurrentContext(); ...
- ILMerge合并程序
在DOS窗口中,进入到ILMerge的安装目录 中 如图所示,之后写合并代码, 使用命令进行捆绑,以如图为例,将CSkin.dll和MyTool.exe捆绑成一个新的newtool.exe文件./ou ...
- java编码转化方案-备用
import java.io.UnsupportedEncodingException; /** * 转换字符串的编码 */ public class changeCharSet { /** 7位AS ...
- 《gzip命令》-linux命令五分钟系列之七
本原创文章属于<Linux大棚>博客. 博客地址为http://roclinux.cn. 文章作者为roc 希望您能通过捐款的方式支持Linux大棚博客的运行和发展.请见“关于捐款” == ...