2008年第33届ACM/ICPC亚洲区预赛(哈尔滨)网络预选赛 1007__The Accomodation of Students 二分图最大匹配+染色
来源:互联网 发布:python text 编辑:程序博客网 时间:2024/04/30 02:47
http://acm.hrbeu.edu.cn/index.php?act=problem&proid=5087
之前完全不会的说....太弱小了
想了半天终于知道啥是染色....
不过现在会了,会了总比不会好-,-
题目的意思就是把学生分成2组,每组中的学生都不互相认识,可是2组间的任何学生都认识,很明显是匹配问题,比赛的时候瞬间被无数人秒杀..
具体思路代码写的非常清楚了...
- #include <iostream>
- using namespace std;
- #define N 201
- bool map[N][N],visit[N];
- int n,m,match[N],color[N];
- bool dfs(int pre)
- {
- for(int i=1;i<=m;i++)
- {
- if(map[pre][i]&&!visit[i])
- {
- visit[i]=true;
- int t=match[i];
- match[i]=pre;
- if(t==-1||dfs(t)) return true;
- match[i]=t;
- }
- }
- return false;
- }
- int find_match()
- {
- memset(match,-1,sizeof(match));
- int i,sum=0;
- for(i=1;i<=n;i++){memset(visit,false,sizeof(visit));if(dfs(i)) sum++;}
- return sum;
- }
- int main()
- {
- int x,y,t;
- bool flag;
- while(cin>>n>>t)
- {
- memset(map,false,sizeof(map));
- memset(color,0,sizeof(color));
- m=n;
- flag=false;
- while(t--)
- {
- cin>>x>>y;
- if(color[x]&&color[x]==color[y])flag=true;
- color[x]=1;
- color[y]=2;
- map[x][y]=true;
- }
- if(flag)
- cout<<"No"<<endl;
- else
- cout<<find_match()<<endl;
- }
- }
- 2008年第33届ACM/ICPC亚洲区预赛(哈尔滨)网络预选赛 1007__The Accomodation of Students 二分图最大匹配+染色
- 2008年第33届ACM/ICPC亚洲区预赛(合肥)网络预选赛_1007 The Luckies number
- HDU 2444 The Accomodation of Students (二分图最大匹配+二分图染色)
- hdu 2444 The Accomodation of Students【二分图染色+最大二分匹配数】
- HDU2444 The Accomodation of Students(染色法判断二分图+最大匹配)
- HDOJ 题目2444 The Accomodation of Students(染色法判二分图,最大匹配)
- hdoj 2444 The Accomodation of Students 【黑白染色判二分图 + 最大匹配】
- hdu2444 The Accomodation of Students (二分图判断+最大匹配)
- hdu2444The Accomodation of Students【判断二分图+最大匹配】
- hdu2444The Accomodation of Students(二分图判断+最大匹配)
- HDU2444The Accomodation of Students(二分图判断+最大匹配)
- hdu2444 The Accomodation of Students【二分图判断+最大匹配】
- hdu 2444 The Accomodation of Students (交叉染色+二分匹配)
- HDU2444 The Accomodation of Students 染色+二分匹配
- HDU2444_The Accomodation of Students _染色法判二分图&邻接矩阵二分图匹配模板
- HDU-2444-The Accomodation of Students [二分匹配][判断二分图][BFS染色法]
- hdu2444 The Accomodation of Students(判断二分匹配+最大匹配)
- 【染色法+二分图匹配】hdu 2444 The Accomodation of Students
- 徐家骏:我在华为工作十年的感悟
- 编写多线程应用程序
- 个人假想
- 计算出你和另一个人的关系
- UI 例子程序
- 2008年第33届ACM/ICPC亚洲区预赛(哈尔滨)网络预选赛 1007__The Accomodation of Students 二分图最大匹配+染色
- 编程排版规范
- 'tasklist' 不是内部或外部命令
- POJ1222
- 暑假实习学习JSP笔记
- POJ1054
- 用好游标
- gnome-commander
- 命名规范