【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 ...
随机推荐
- java中for循环的6种写法
有些写法上的说明写的过于武断,可能有很多不当之处,仅供参考. package ForLoop; import java.util.ArrayList; import java.util.Itera ...
- codevs 3119 高精度练习之大整数开根 (各种高精+压位)
/* codevs 3119 高精度练习之大整数开根 (各种高精+压位) 二分答案 然后高精判重 打了一个多小时..... 最后还超时了...压位就好了 测试点#1.in 结果:AC 内存使用量: 2 ...
- PL/SQL 嵌套表变长数组和索引表[转]
关于PL/SQL中这三种数组的介绍,不想写了.转一篇日志吧…… 链接:http://www.blogjava.net/decode360/archive/2008/08/08/280825.html ...
- C++ 简单的入门语法
入门的hello world using namespace std; 是使用命名空间,有点像java里面的引入包main 方法和java一样是主入口,有且只有一个,因为是int ,所以还必须返回一个 ...
- webUploader上传组件 实际运用小结
WebUploader组件实际介绍: 官网:http://fex.baidu.com/webuploader/doc/index.html 组件优势及优化总结:http://itindex.net/d ...
- CSS3 颜色值HSL表示方式&简单实例
HSL色彩模式:就是色调(Hue).饱和度(Saturation).亮度(Lightness)三个颜色通道的改变以及它们相互之间的叠加来获得各种颜色,色调(Hue)色调最大值360,饱和度和亮度有百分 ...
- java simple check whether a file or directory.
Ref: check whether a file or directory First, make sure the path exists by using: new File(path).ex ...
- asp.net中ashx文件如何调用session
如果你要保证数据的安全性,你可以在ashx中使用session验证.如:你的index.aspx中使用jquery回调ashx数据,那么在index.aspx page_load时session[&q ...
- 关于cocoapods和swift中使用oc第三方
mac 系统自带ruby,使用cocoapods,直接安装cocoapods就行 终端:$ sudo gem install cocoapods {安装较慢是因为有墙,查看ruby镜像列表:$ gem ...
- 在万网虚拟主机上部署MVC5
参考 要想部署mvc,需要把一些mvc用到的全局程序集改为本地部署,通过N次试验,终于搞定. 特写个备忘录,免得以后忘了. 首先更改web.config,在里面加上 <system.web> ...