图论的题目。着色原理+二分图匹配。

 #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的更多相关文章

  1. hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS     Me ...

  2. HDU 2444 The Accomodation of Students 二分图判定+最大匹配

    题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...

  3. HDOJ 2444 The Accomodation of Students

    染色判读二分图+Hungary匹配 The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limi ...

  4. hdu 2444 The Accomodation of Students 判断二分图+二分匹配

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  5. HDU 2444 The Accomodation of Students(判断二分图+最大匹配)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  6. HDU——2444 The Accomodation of Students

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  7. hdu 2444 The Accomodation of Students (判断二分图,最大匹配)

    The Accomodation of StudentsTime Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  8. hdu 2444 The Accomodation of Students(二分匹配 匈牙利算法 邻接表实现)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. 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 ...

随机推荐

  1. MapReduce实战:统计不同工作年限的薪资水平

    1.薪资数据集 我们要写一个薪资统计程序,统计数据来自于互联网招聘hadoop岗位的招聘网站,这些数据是按照记录方式存储的,因此非常适合使用 MapReduce 程序来统计. 2.数据格式 我们使用的 ...

  2. Win7设置承载网络 分类: 网络 2014-10-30 09:08 105人阅读 评论(0) 收藏

    Win7设置承载网络 (1)最重要的第一步,要知道自己的网卡是否支持承载网络,如果不支持就悲剧地一票否决了,支持的话才能开始以后各步骤的设置. netsh wlan show drivers (2)设 ...

  3. java构造函数也可以用private开头

    private 构造函数一般用于Singleton模式,指的是整个应用只有本类的一个对象,一般这种类都有一个类似getInstance()的方法!下面是一个Singleton的例子:public cl ...

  4. angularjs modal模态框----创建可拖动的指令

    //最近项目中需要将angular-ui-bootstrap中用到的弹出框,使之可拖动,由于源文件中没有实现,需要自己实现指令,以下即为该指令,亲测可以实现..directive('draggable ...

  5. OC - 26.CAAnimationGroup

    概述 简介 CAAnimationGroup又称组动画或动画组 将多个动画放到动画组中,并赋值给layer的animations属性,动画组中所有动画就会并发执行 注意事项 动画组中的动画不会被压缩, ...

  6. EMA计算的C#实现(c# Exponential Moving Average (EMA) indicator )

    原来国外有个源码(TechnicalAnalysisEngine src 1.25)内部对EMA的计算是: var copyInputValues = input.ToList(); for (int ...

  7. [转]mysql自动定时备份数据库的最佳方法-支持windows系统

    网上有很多关于window下Mysql自动备份的方法,可是真的能用的也没有几个,有些说的还非常的复杂,难以操作. 我们都知道mssql本身就自带了计划任务可以用来自动备份,可是mysql咱们要怎么样自 ...

  8. Mac使用rz、sz远程上传下载文件

    习惯了 在windows下的securecrt和xshell的rz 和sz. rz 可以很方便的从客户端传文件到服务器,sz也可以很方便的从服务器传文件到客户端,就算中间隔着跳板机也不影响.在mac下 ...

  9. 初涉JavaScript模式 (1) : 简介

    什么是模式? 广义上的模式是指 :在物体或事件上,产生的一种规律变化与自我重复的样式与过程.在模式之中,某些固定的元素不断以可预测的方式周期性重现.最基本而常见的模式,称为密铺,具备重复性以及周期性两 ...

  10. 分数拆分( Fractions Again, UVA 10976)-ACM

    It is easy to see that for every fraction in the form  (k > 0), we can always find two positive i ...