poj 1274 The Prefect Stall - 二分匹配
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 22736 | Accepted: 10144 |
Description
Given the preferences of the cows, compute the maximum number of milk-producing assignments of cows to stalls that is possible.
Input
Output
Sample Input
Sample Output
Source
这道题没有什么特别好说的,直接匈牙利算法不解释
Code:
/**
* poj.org
* Problem#1274
* Accepted
* Time:16ms
* Memory:520k/540k
*/
#include<iostream>
#include<queue>
#include<set>
#include<map>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<stdarg.h>
#include<fstream>
#include<ctime>
using namespace std;
typedef bool boolean;
typedef class Edge {
public:
int end;
int next;
Edge():end(),next(){}
Edge(int end, int next):end(end),next(next){}
}Edge;
int *h;
int _count = ;
Edge* edge;
inline void addEdge(int from,int end){
edge[++_count] = Edge(end,h[from]);
h[from] = _count;
}
int result;
int *match;
boolean *visited;
boolean find(int node){
for(int i = h[node];i != ;i = edge[i].next){
if(visited[edge[i].end]) continue;
visited[edge[i].end] = true;
if(match[edge[i].end] == -||find(match[edge[i].end])){
match[edge[i].end] = node;
return true;
}
}
return false;
}
int n,m;
void solve(){
for(int i = ;i <= n;i++){
if(match[i] != -) continue;
memset(visited, false, sizeof(boolean) * (n + m + ));
if(find(i)) result++;
}
}
int buf;
int b;
boolean init(){
if(~scanf("%d%d",&n,&m)){
result = ;
visited = new boolean[(const int)(n + m + )];
match = new int[(const int)(n + m + )];
edge = new Edge[(const int)((n * m) + )];
h = new int[(const int)(n + m + )];
memset(h, , sizeof(int)*(n + m + ));
memset(match, -,sizeof(int)*(n + m + ));
for(int i = ;i ^ n;i++){
scanf("%d",&buf);
for(int j = ;j ^ buf;j++){
scanf("%d",&b);
addEdge(i + , b + n);
// addEdge(b + n, i + 1);
}
}
return true;
}
return false;
}
void freeMyPoint(){
delete[] visited;
delete[] match;
delete[] edge;
delete[] h;
}
int main(){
while(init()){
solve();
printf("%d\n",result);
freeMyPoint();
}
return ;
}
poj 1274 The Prefect Stall - 二分匹配的更多相关文章
- poj 1274 The Perfect Stall (二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17768 Accepted: 810 ...
- [题解]poj 1274 The Prefect Stall
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22736 Accepted: 10144 Description Far ...
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配)
Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配) Description 农夫约翰上个 ...
- poj——1274 The Perfect Stall
poj——1274 The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25709 A ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- [题解]poj 1274 The Perfect Stall(网络流)
二分匹配传送门[here] 原题传送门[here] 题意大概说一下,就是有N头牛和M个牛棚,每头牛愿意住在一些牛棚,求最大能够满足多少头牛的要求. 很明显就是一道裸裸的二分图最大匹配,但是为了练练网络 ...
- POJ-1274The Perfect Stall,二分匹配裸模板题
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23313 Accepted: 103 ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
随机推荐
- Maven中的pom.xml配置文件详解
原文:http://blog.csdn.net/u012152619/article/details/51485297 <project xmlns="http://maven.apa ...
- 【JMeter】如何录制创建及得到曲线图
前段时间公司需要对服务器进行压力测试,包括登录前的页面和登录后的页面,主要目的是测试负载均衡的实现效果.不知道是不是因为Jmeter不如loadRunner火爆还是什么,网上关于Jmeter的资料有很 ...
- BUG笔记:Android原生浏览器不认负百分数margin致Foundation Orbit往右滑动动画出错
一看这标题就知道无比蛋疼了是不?至少我从来不用安卓自带的浏览器... 发现这个bug的场景:万恶的Foundation,它的滚动图片插件Orbit在安卓自带浏览器下手指从左往右滑动时动画仍旧表现为从右 ...
- Unity注意事项
1.尽量避免出现中文路径 2.做2D游戏时,图片最好要与背景图片保持一定距离 以免重叠
- Git、bower 安装
1>下载并安装nodejs .老师分享的nodejs版本“node-v8.9.4-x64” 下载页面http://nodejs.cn/download/ 一直无脑下一步操作即可安装完毕 ...
- 不需要更多JS框架了
现在,JavaScript框架已成为Web项目开发不可或缺的一部分.那是因为很长一段时间以来,各种浏览器之间有很大的差别,人们不得不编写框架对此进行屏蔽.问题在于,各种浏览器甚至在基本问题上都难以取得 ...
- [py]str list切片-去除字符串首尾空格-递归思想
取出arr的前几项 #方法1 print([arr[0], arr[1]]) #方法2 arr2 = [] for i in range(2): arr2.append(arr[i]) print(a ...
- 浏览器 extension和plugin的区别[来自知乎]
"扩展"和"插件",其实都是软件组件的一种形式,Chrome 只不过是把两种类型的组件分别给与了专有名称,一个叫"扩展",另一个叫" ...
- numpy的prod()函数和pad()函数
1.np.prod()函数用来计算所有元素的乘积,对于有多个维度的数组可以指定轴,如axis=1指定计算每一行的乘积. 2.np.lib.pad()函数用来把原来的list在原来的维度上进行扩展 例1 ...
- vs2010用NuGet(程序包管理)安装EF失败之解决办法
今天用程序包管理控制台安装EF.报错.如下