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. python文本 字符串逐字符反转以及逐单词反转

    python文本 字符串逐字符反转以及逐单词反转 场景: 字符串逐字符反转以及逐单词反转 首先来看字符串逐字符反转,由于python提供了非常有用的切片,所以只需要一句就可以搞定了 >>& ...

  2. Extjs DateField onchange

    1 开发思路: 在日期值变化的事件中获得选择后的日期值,传给后台,然后从后台加载相应的数据 2 问题:在查看extjs2.2 的api的官方说明文档,文档对datefield组件的change事件说明 ...

  3. Selenium2+python自动化34-获取百度输入联想词

    前言 最近有小伙伴问百度输入后,输入框下方的联想词如何定位到,这个其实难度不大,用前面所讲的元素定位完全可以定位到的. 本篇以百度输入框输入关键字匹配后,打印出联想词汇. 一.定位输入框联想词 1.首 ...

  4. Google Ads原理

    Google AdSense广告会根据访问者的地理IP,显示不同的广告,因为adwords里面有相应的设置,有些广告商只想把广告显示给某一地理区域的客户.另一方面就是同一个网站,你在日本和美国会看到日 ...

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

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

  6. go语言之进阶篇方法面向过程和对象函数的区别

    1.方法 (method) 在面向对象编程中,一个对象其实也就是一个简单的值或者一个变量,在这个对象中会包含一些函数,这种带有接收者的函数,我们称为方法(method). 本质上,一个方法则是一个和特 ...

  7. Vulkan --vulkan in powervr

    zhankeng 跨平台 多线程 low cpu overhead object orientated vulkan有利于tile based的地方 明确依赖声明 细粒度同步 render passe ...

  8. request和request.form和request.querystring的区别

    asp中获取传递的参数,一般用request或者用request成员函数request.form,两种方式都可以获取页面表单传递过来的参数值,一直没留意两种方法有什么区别,我一般喜欢用request( ...

  9. Java基础(八):多态

    一.多态的理解: 多态是同一个行为具有多个不同表现形式或形态的能力. 多态就是同一个接口,使用不同的实例而执行不同操作,如图所示: 多态性是对象多种表现形式的体现:现实中,比如我们按下 F1 键这个动 ...

  10. 第三章:ES分词简单说明

    1. Index_Analyzer为索引时使用的分词器,search_Analyzer为搜索时使用的分词器 这个索引,对应的数据是下图: 数据格式是用%分隔的年份,"index_analyz ...