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 ...
随机推荐
- Integral transform 积分变换
总结: 1.为了更加便于求解,将方程从原域映射到另外一个域 Integral transform - Wikipedia https://en.wikipedia.org/wiki/Integral_ ...
- pandas2
1.Series创建的方法统一为pd.Series(data,index=)(1,2,3)Series可以通过三种形式创建:python的dict.numpy当中的ndarray(numpy中的基本数 ...
- IO、NIO、AIO理解
摘要: 关于BIO和NIO的理解 最近大概看了ZooKeeper和Mina的源码发现都是用Java NIO实现的,所以有必要搞清楚什么是NIO.下面是我结合网络资料自己总结的,为了节约时间图示随便画的 ...
- Linux计划任务Crontab学习笔记
1 http://www.jb51.net/LINUXjishu/345698.html 2 http://www.jb51.net/LINUXjishu/345705.html 3 http: ...
- Python开发【笔记】:what?进程queue还能生产出线程!
进程queue底层用线程传输数据 import threading import multiprocessing def main(): queue = multiprocessing.Queue() ...
- router-link params传参
1.router.js配置 需要在路径后定义上要传的属性名 --> /:属性名(query方式不需要) { path: '/CreateProgress/:name1', name: ...
- 洛谷P3209平面图判定 [HNOI2010] 2-sat
正解:2-sat(并茶几/强连通分量 解题报告: 传送门w 难受死了,连WA5次,正确率又-=INF了QAQ 然后先说下这题怎么做再来吐槽自己QAQ 首先这题其实和NOIp2010的关押罪犯挺像的,然 ...
- C#静态类,静态构造函数,静态变量
静态变量位于栈上,它是一个全局变量,在编译期就已经生成. public class Cow public static int count; private int id; { id = ++coun ...
- Java-idea-生成for循环
itar 生成array for代码块 for (int i = 0; i < array.length; i++) { = array[i]; } itco 生成Collection迭代 fo ...
- 从浏览器输入参数,到后台处理的vertx程序
vertx由于性能较高,逐渐变得流行.下面将一个vertx的入门案例. 添加依赖 <!-- vertx --> <dependency> <groupId>io.v ...