【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 ...
随机推荐
- linux 内核分析+使用SystemTap调试新增内核模块
http://blog.chinaunix.net/uid/14528823/list/1.html?cid=189394
- Qt 学习之路 :使用 QJson 处理 JSON
XML 曾经是各种应用的配置和传输的首选方式.但是现在 XML 遇到了一个强劲的对手:JSON.我们可以在 这里 看到有关 JSON 的语法.总体来说,JSON 的数据比 XML 更紧凑,在传输效率上 ...
- CSS3伪类nth-child结合transiton动画实现文字若影若现
css3伪类nth-child结合transiton动画实现文字若影若现收先创建一个div盒子,然后包裹在div中的有10个span标签每个span标签填上内容一次为A,B,C,D,E,F,G,H,I ...
- maven占位符
maven占位符默认是${} 也可以自己指定. pom.xml配置如下: <plugin> <groupId>org.apache.maven.plugins</grou ...
- jdbc - Insert 'Date' value in PreparedStatement
“preparedStatement.setDate()”方法接受的是 'java.sql.Date' 类型的参数,而我们一般格式化日期所使用的是'java.util.Date'中的'SimpleDa ...
- Convention插件的使用(会涉及content目录,jsp必须放入这个下面才能映射成功基于注解的配置)
http://blog.csdn.net/zclandzzq/article/details/7107816
- 关于ios8斯坦福公开课第二课
在这个课程中,我们遇到了这样的代码 @IBAction func oprate(sender: UIButton) { let opration = sender.currentTitle! if u ...
- 解决Undefined symbols for architecture x86_64: 报错 和 ld: warning: ld: warning: ignoring file警告
出现这种错误的情况: 用iphone5模拟器编译程序正常, 用iphone5s以上的模拟器编译出现Undefined symbols for architecture x86_64: 报错 和 ld: ...
- JavaScript中style.left与offsetLeft的区别
今天在制作焦点轮播图的时候,遇到一个问题,在使用style.left获取图片的位置时,怎么也获取不到.换用offsetLeft就能够成功获取到了.虽然实现了我想要的效果,但是还是不甘心啊,没有找到原因 ...
- 【深度解析】Google第二代深度学习引擎TensorFlow开源
作者:王嘉俊 王婉婷 TensorFlow 是 Google 第二代深度学习系统,今天宣布完全开源.TensorFlow 是一种编写机器学习算法的界面,也可以编译执行机器学习算法的代码.使用 Tens ...