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

 #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. PHP编译安装出错configure: error: mcrypt.h not found. Please reinstall libmcrypt的解决办法

    1.下载libmcrypt wget http://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.ta ...

  2. HDFS的Java客户端操作代码(查看HDFS下所有的文件或目录)

    1.查看HDFS下所有的文件或目录 package Hdfs; import java.io.IOException; import java.net.URI; import org.apache.h ...

  3. 利用Graphviz 画结构图[转]

    转自:http://www.cnblogs.com/sld666666/archive/2010/06/25/1765510.html 利用Graphviz 画结构图   1. Graphviz介绍 ...

  4. 国际化 native2ascii用法

    cmd下输入: native2ascii -encoding GBK(需要编译成哪种语言) (中文文件路劲) (英文文件路劲) 其他固定 例如 native2ascii -encoding GBK C ...

  5. 微信小程序开发之入门篇(熟悉项目结构)

    微信小程序创建之后会生成一个项目模板,如下图所示(基本如此,但并不局限于此) 现在分别来说明一下每个文件及目录的意思 app.js 程序的入口文件,必须存在. app.js是小程序的脚本代码.我们可以 ...

  6. 使用SQL Server 2008远程链接时SQL数据库不成功的解决方法

    关键设置: 第一步(SQL2005.SQL2008): 开始-->程序-->Microsoft SQL Server 2008(或2005)-->配置工具-->SQL Serv ...

  7. 2016.7.13final 修饰符使用

    final修饰符可以修饰类.变量.函数: 1.被final所修饰的类不能被继承,函数不能被继承,成员变量不能再次被赋值并且被称为常量: 2.被final 修饰的成员变量 .它通常被static所修饰, ...

  8. SGU 168.Matrix

    时间限制:0.5s 空间限制:15M 题意: 给出一个N*M的矩阵A,计算矩阵B,满足B[i][j]=min{ A[x][y]:(y>=j) and ( x>=i+j-y )} Solut ...

  9. SGU 175.Encoding

    Solution: 简单题. 答案初始化为1. 从给定的n,q往下推出新的n和q,如果q是在右半边,答案加上 n-n/2. 一直到推到n==1. code: #include <iostream ...

  10. 第三篇、调优之路 Apache调优

    1.  简介 在第一篇中整合了apache + tomcat ,利用了apache解析静态文件为tomcat解压.但是在测试机上发现两者性能不足,不能充分利用服务器的性能,该篇中将对apache进行性 ...