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
2 2 2
1 2
2 1

Sample Output

Case 1: 2

Source

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

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

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

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAXN = 110; int g[MAXN][MAXN], vis[MAXN];
int lined[MAXN];
int n, m, e; int dfs(int u) {
for (int v = 1; v <= m; v++) {
if (g[u][v] && !vis[v]) {
vis[v] = 1;
if (lined[v] == -1 || dfs(lined[v])) {
lined[v] = u;
return 1;
}
}
}
return 0;
} int main() {
int t, cas = 1;;
scanf("%d", &t);
while (t--) {
memset(g, 1, sizeof(g));
memset(lined, -1, sizeof(lined));
scanf("%d%d%d", &n, &m, &e);
for (int i = 0; i < e; i++) {
int a, b;
scanf("%d%d", &a, &b);
g[a][b] = 0;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
memset(vis, 0, sizeof(vis));
if (dfs(i))
ans++;
}
printf("Case %d: ", cas++);
printf("%d\n", ans);
}
return 0;
}

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. AD域 根据 用户属性userAccountControl 来判断用户禁用属性

    参考:https://support.microsoft.com/zh-cn/help/305144/how-to-use-the-useraccountcontrol-flags-to-manipu ...

  2. VMware+Windgb+Win7内核驱动调试

    com1被占用了,需要用com2

  3. LinkedList剖析

    第1部分 LinkedList介绍 LinkedList简介 LinkedList 是一个继承于AbstractSequentialList的双向链表.它也可以被当作堆栈.队列或双端队列进行操作. D ...

  4. 第六章 HashSet源码解析

    6.1.对于HashSet需要掌握以下几点 HashSet的创建:HashSet() 往HashSet中添加单个对象:即add(E)方法 删除HashSet中的对象:即remove(Object ke ...

  5. 7 个 Bootstrap 在线编辑器用于快速开发响应式网站

    Bootstrap 已经使响应式网站开发变得简单很多. 但是如果你不必手动写全部代码,事情会如何呢? 如果你可以自由地选择你想要使用的Bootstrap 组件.并可以把它们拖拽到画布中,事情会如何呢? ...

  6. 一款超炫的jquery图片播放插件[Cloud Carousel]

    今天给大家介绍一个jquery图片播放插件,也可以说是一款幻灯片放映插件,它叫Cloud Carousel,支持自动播放.图片预览.鼠标滚轮滚动,非常酷,下图是效果预览. 该jquery图片播放项目演 ...

  7. SQL基础(三):SQL命令

    下面2个表用于实例演示: 1.SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的每个 SELECT 语句必须拥有相同数量的列.列 ...

  8. Android之AlarmManager

    Android平台中,Alarm Manager Service控制着闹钟和唤醒功能.和其他系统服务一样,提供了一个辅助管理类-AlarmManager,我们只需要使用AlarmManager即可调用 ...

  9. idea unicode自动转码设置

    idea unicode自动转码设置 File > Settings > Editor > File Encodings 右侧 Properties Files 中 选中 Trans ...

  10. ios之开发者须知常见简写英文代表的含义

    <span style="white-space:pre"> </span> //NS基本 //MK地图 //CG图形绘制 //AV视音频 //UI视图 / ...