hdu 2444 The Accomodation of Students
来源:互联网 发布:启翔网络 编辑:程序博客网 时间:2024/04/27 13:57
1.先判断是否为二分图:一边的标记为1,另一边标记为2,如果两边都是1或者都是2的话,就说明不是二分图,我使用的是直接使用两个for进行循环,即可判断。
2.再找二分图的最大匹配。
http://acm.hdu.edu.cn/showproblem.php?pid=2444
#include <stdio.h>#include <stdlib.h>#include <string.h>#define maxn 205int vis[maxn];int mp[maxn][maxn];int n,m,mark ;int g[maxn];int findx(int a1){ int i; for(i=1;i<=n;i++){ if(mp[a1][i]==1&&vis[i]==0){ vis[i] = 1; if(g[i]==0||findx(g[i])){ g[i] = a1; return 1; } } } return 0;}int main(void){ int i,j,tempa,tempb,ans; while(~scanf("%d %d",&n,&m)){ memset(mp,0,sizeof(mp)); for(i=0;i<m;i++){ scanf("%d %d",&tempa,&tempb); mp[tempa][tempb] = 1; } mark = 0; memset(vis,0,sizeof(vis)); for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if(mp[i][j]==1){ if(vis[i]==0&&vis[j]==0){ vis[i] = 1;vis[j] = 2; } else if(vis[i]==vis[j]){ mark = 1; break; } else if(vis[i]>0){ if(vis[i]==1)vis[j] = 2 ; else vis[j] = 1; } else{ if(vis[j]==1)vis[i] = 2; else vis[i] = 1; } } } if(mark)break; } if(mark){puts("No");continue;} ans = 0; memset(g,0,sizeof(g)); for(i=1;i<=n;i++){ memset(vis,0,sizeof(vis)); ans += findx(i); } printf("%d\n",ans); }}
0 0
- hdu 2444 The Accomodation of Students
- hdu 2444 The Accomodation of Students
- hdu 2444 The Accomodation of Students
- hdu 2444 The Accomodation of Students
- HDU 2444 The Accomodation of Students
- hdu 2444 The Accomodation of Students
- hdu 2444 The Accomodation of Students
- HDU 2444 The Accomodation of Students
- HDU - 2444 The Accomodation of Students
- hdu acm 2444 The Accomodation of Students
- 【HDU】 2444 The Accomodation of Students
- #HDU 2444 The Accomodation of Students
- hdu 2444 The Accomodation of Students
- The Accomodation of Students HDU
- The Accomodation of Students HDU
- The Accomodation of Students HDU
- hdu 2444-The Accomodation of Students(二分匹配)
- hdu 2444 The Accomodation of Students 二分匹配
- UIWebView 自适应高度
- 手机wap浏览器下载选哪家
- 场景管理器 -----OGRE 3D 1.7 Beginner‘s Guide中文版 第六章
- HashMap经典存储案例,分拣思路_与面向对象组合解题
- SSH注解插入数据库时间类型 时分秒丢失的问题
- hdu 2444 The Accomodation of Students
- 【Android】下载文件:进度条和通知栏
- [iOS错误汇总]libc++abi.dylib: terminating with uncaught exception of type NSException
- python Web开发框架-Django (2)
- change dir color in terminal
- C++ 中SQLITE3 判断表是否存在
- android:largeHeap介绍
- 物联12:高频基站芯片--MF RC500介绍
- 使用VS调试Unity脚本