标签:
Description
Input
Output
Sample Input
Sample Output
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int ms[101][101],match[101],vis[101]; int n,m; int hungray(int u){ for(int i = 1;i<=m;i++){ if(ms[u][i] && vis[i] == 0){ vis[i] = 1; if(match[i] == 0||hungray(match[i])){ match[i] = u; return 1; } } } return 0; } int main(){ int k; int c = 1; while(~scanf("%d%d%d",&n,&m,&k)){ int ans,res; ans = res = 0; memset(ms,0,sizeof(ms)); memset(match,0,sizeof(match)); int x,y; for(int i = 0;i<k;i++){ scanf("%d%d",&x,&y); ms[x][y] = 1; } for(int i = 1;i<= n;i++){ memset(vis,0,sizeof(vis)); if(hungray(i))ans ++; } int match1[101]; for(int i = 1;i<=m;i++)match1[i] = match[i]; for(int i = 1;i<= m;i++){ memset(match,0,sizeof(match)); int ans1 = 0; if(match1[i]){ // printf("匹配为:%d %d\n",match[i],i); ms[match1[i]][i] = 0; for(int j = 1;j<=n;j++){ memset(vis,0,sizeof(vis)); if(hungray(j))ans1++; } if(ans1 < ans)res++; ms[match1[i]][i] = 1; } } //printf("%d %d\n",res,ans); printf("Board %d have %d important blanks for %d chessmen.\n",c++,res,ans); } }
标签:
原文地址:http://www.cnblogs.com/lovelystone/p/4701257.html