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

  1. 1
  2. 2 2 2
  3. 1 2
  4. 2 1

Sample Output

  1. Case 1: 2

Source

2011年全国大学生程序设计邀请赛(福州)

题意:有n个人分别相应不喜欢某个宠物,问最多能卖出去几仅仅

思路:简单的二分图匹配。匈牙利算法模板

  1. #include <iostream>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cstdio>
  5. using namespace std;
  6. const int MAXN = 110;
  7.  
  8. int g[MAXN][MAXN], vis[MAXN];
  9. int lined[MAXN];
  10. int n, m, e;
  11.  
  12. int dfs(int u) {
  13. for (int v = 1; v <= m; v++) {
  14. if (g[u][v] && !vis[v]) {
  15. vis[v] = 1;
  16. if (lined[v] == -1 || dfs(lined[v])) {
  17. lined[v] = u;
  18. return 1;
  19. }
  20. }
  21. }
  22. return 0;
  23. }
  24.  
  25. int main() {
  26. int t, cas = 1;;
  27. scanf("%d", &t);
  28. while (t--) {
  29. memset(g, 1, sizeof(g));
  30. memset(lined, -1, sizeof(lined));
  31. scanf("%d%d%d", &n, &m, &e);
  32. for (int i = 0; i < e; i++) {
  33. int a, b;
  34. scanf("%d%d", &a, &b);
  35. g[a][b] = 0;
  36. }
  37. int ans = 0;
  38. for (int i = 1; i <= n; i++) {
  39. memset(vis, 0, sizeof(vis));
  40. if (dfs(i))
  41. ans++;
  42. }
  43. printf("Case %d: ", cas++);
  44. printf("%d\n", ans);
  45. }
  46. return 0;
  47. }

FZU - 2039 Pets (二分图匹配 2011年全国大学生程序设计邀请赛(福州))的更多相关文章

  1. fzu 2039 Pets (简单二分图 + (最大流 || 二分图))

    Are you interested in pets? There is a very famous pets shop in the center of the ACM city. There ar ...

  2. UVA 2039 Pets(网络流)

    Problem Description Are you interested in pets? There is a very famous pets shop in the center of th ...

  3. 博弈论(二分图匹配):NOI 2011 兔兔与蛋蛋游戏

    Description Input 输入的第一行包含两个正整数 n.m. 接下来 n行描述初始棋盘.其中第i 行包含 m个字符,每个字符都是大写英文字母"X".大写英文字母&quo ...

  4. HDOJ 5093 Battle ships 二分图匹配

    二分图匹配: 分别按行和列把图展开.hungary二分图匹配. ... 例子: 4 4 *ooo o### **#* ooo* 按行展开. .. . *ooo o#oo oo#o ooo# **#o ...

  5. hdu 3829 Cat VS Dog 二分图匹配 最大点独立集

    Cat VS Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Prob ...

  6. HDOJ 5090 Game with Pearls 二分图匹配

    简单的二分图匹配: 每个位置可以边到这些数字甚至可以边 Game with Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  7. UVA 12549 - 二分图匹配

    题意:给定一个Y行X列的网格,网格种有重要位置和障碍物.要求用最少的机器人看守所有重要的位置,每个机器人放在一个格子里,面朝上下左右四个方向之一发出激光直到射到障碍物为止,沿途都是看守范围.机器人不会 ...

  8. POJ 1274 裸二分图匹配

    题意:每头奶牛都只愿意在她们喜欢的那些牛栏中产奶,告诉每头奶牛愿意产奶的牛棚编号,求出最多能分配到的牛栏的数量. 分析:直接二分图匹配: #include<stdio.h> #includ ...

  9. BZOJ1433 ZJOI2009 假期的宿舍 二分图匹配

    1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2375  Solved: 1005[Submit][Sta ...

随机推荐

  1. CMMI管理体系

    帮助企业对软件工程过程进行管理和改进,增强开发与改进能力,从而按时,不超过预算地开发软件. CMMI为改进一个组织的各种过程提供了一个单一的集成化框架,新的集成模块框架消除了各个模型的不一致性,减少了 ...

  2. 基于非比較的排序:计数排序(countSort),桶排序(bucketSort),基数排序(radixSort)

    计数排序 条件:要排序的数组的元素必须是在一定范围的,比方是1~100.在排序之前我们必须知道数组元素的范围. 思路:顾名思义:就是用一个数组来计数的. 步骤: 1.用一个数组来计数count[ ], ...

  3. Mysql中与时间相关的统计分析

    最近项目需要统计一段日期范围内,根据每分钟.几分钟.每天分别统计汇总某些事件/指标的发生总次数,平均发生次数,因此总结了Mysql中与时间处理.统计相关的资料. 按分钟统计某一时间段内的数据 SELE ...

  4. poj 1007 Quoit Design(分治)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. 不错网络性能相关的文章-BaiduRPC

    http://wiki.baidu.com/display/RPC/Threading+Overview#ThreadingOverview-单线程reactor Threading Overview ...

  6. 第二章 Jackson属性名转换+属性忽略

    @Data @JsonIgnoreProperties(ignoreUnknown = true) public class MyRecord { private boolean succeed; p ...

  7. Python并发编程-Memcached (分布式内存对象缓存系统)

    一.Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的 ...

  8. jQuery多媒体播放器插件jQuery Media Plugin使用方法

    jQuery Media Plugin是一款基于jQuery的网页媒体播放器插件,它支持大部分的网络多媒体播放器和多媒体格式,比如:Flash, Windows Media Player, Real ...

  9. IOS中的动画——Core Animation

    一.基础动画 CABasicAnimation //初始化方式 CABasicAnimation * cabase=[CABasicAnimation animation]; //通过keyPath设 ...

  10. MongoDB学习笔记(三)--权限 && 导出导入备份恢复 && fsync和锁

    权限                                                                                             绑定内网I ...