FZU 2039-Pets(二分图_最大匹配)
来源:互联网 发布:数据对比分析方法 编辑:程序博客网 时间:2024/05/18 01:23
Accept: 302 Submit: 795
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Are you interested in pets? There is a very famous pets shop in the center of the ACM city. There are totally m pets in the shop, numbered from 1 to m. One day, there are n customers in the shop, which are numbered from 1 to n. In order to sell pets to as more customers as possible, each customer is just allowed to buy at most one pet. Now, your task is to help the manager to sell as more pets as possible. Every customer would not buy the pets he/she is not interested in it, and every customer would like to buy one pet that he/she is interested in if possible.
Input
There is a single integer T in the first line of the test data indicating that there are T(T≤100) test cases. In the first line of each test case, there are three numbers n, m(0≤n,m≤100) and e(0≤e≤n*m). Here, n and m represent the number of customers and the number of pets respectively.
In the following e lines of each test case, there are two integers x(1≤x≤n), y(1≤y≤m) indicating that customer x is not interested in pet y, such that x would not buy y.
Output
For each test case, print a line containing the test case number (beginning with 1) and the maximum number of pets that can be sold out.
Sample Input
Sample Output
Source
2011年全国大学生程序设计邀请赛(福州)思路:基本上是个裸地二分图求最大匹配,这个就是建图有点不同,和一般的二分图反过来标记。
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const double pi= acos(-1.0);int mp[1010][1010];int vis[1010];int link[1010];int n,m;int dfs(int x){ int i; for(i=1;i<=m;i++){ if(mp[x][i]||vis[i]) continue; vis[i]=1; if(link[i]==-1||dfs(link[i])){ link[i]=x; return 1; } } return 0;}int main(){ int T,i; int q; int x,y; int icase=1; scanf("%d",&T); while(T--){ memset(mp,0,sizeof(mp)); memset(link,-1,sizeof(link)); scanf("%d %d %d",&n,&m,&q); while(q--){ scanf("%d %d",&x,&y); mp[x][y]=1; } int cnt=0; for(i=1;i<=n;i++){ memset(vis,0,sizeof(vis)); if(dfs(i)) cnt++; } printf("Case %d: %d\n",icase++,cnt); } return 0;}
- FZU 2039-Pets(二分图_最大匹配)
- FZU 2039 Pets 二分图匹配
- FZU 2039 Pets【二分匹配】
- FZU - 2039 Pets(二分图匹配/匈牙利算法)
- fzu 2039 Pets (简单二分图 + (最大流 || 二分图))
- FZU 2039 Pets(二分匹配裸题)
- FZU - 2039 Pets (二分图匹配 2011年全国大学生程序设计邀请赛(福州))
- fzu 2039(二分图匹配)
- FZU2039 Pets 二分匹配
- FZU 2039 pets
- FZU - 2039 Pets
- fzu 2039 Pets(网络流最大流)
- FZU - 2039 Pets (网络流最大流)
- FZU 2232 炉石传说(二分图最大匹配)
- 二分图最大匹配_基础 - Chessboard
- fzu 2039 Pets(网络流)
- FZU 2039 Pets(匈牙利算法)
- 过山车(二分图_求最大匹配数)
- php常用字符串处理函数
- 时间序列的归一化方法
- 2015年腾讯安全技术笔试经验分享
- 创建第一个SPA应用--2015-03-30记录
- 并查集 Table问题
- FZU 2039-Pets(二分图_最大匹配)
- LBS的球面距离计算及Geohash方案探讨(LBS之一)
- MFC编程学习经验一
- 使用JSONExport生成model文件
- HDU 1213 How Many Tables
- 关于斐波那契数列的递推与递归实现
- 【j2ee spring】11、整合SSH框架之添加一个成员
- php数组用法 与 常用数组函数
- bzoj 3916: [Baltic2014]friends