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 ...
随机推荐
- Oracle备份恢复之无备份情况下恢复undo表空间
UNDO表空间存储着DML操作数据块的前镜像数据,在数据回滚,一致性读,闪回操作,实例恢复的时候都可能用到UNDO表空间中的数据.如果在生产过程中丢失或破坏了UNDO表空间,可能导致某些事务无法回滚, ...
- 判断tableViewCell是否在可视区
1.- (NSArray *)visibleCells; UITableview 的方法,这个最直接,返回一个UITableviewcell的数组. 对于自定义的cell,之后的处理可能会稍微复杂. ...
- PL/SQL EXCEPTION捕获抛出异常
EXCEPTION抛出异常 处理除数为零异常 declare varA number; begin varA:=10/0; dbms_output.put_line('IT WILL NOT WORK ...
- mongodb基础语法
Mongodb与关系型数据库最大的区别就是无约束, 既无字段(外键等)约束, 也没有数据类型约束, 以json存储 安装 启动Mongodb(默认在c盘找 data/db/文件夹) 服务端: mong ...
- hbuilder 打包app简易教程
1. 新建app 2. 新建弹窗面板中选择MUi登录模版 ps:在弹出的窗口,填入应用名称,根据需求选择项目位置,以及模板内容. 3. 检验app效果 菜单栏 -> 运行 -> 手机运行 ...
- 【Pyton】【小甲鱼】爬虫
一.什么是爬虫? 可以理解为一只蜘蛛,在不同的网页上爬来爬去,获取我们需要的资源 二.Python如何访问互联网 urllib(一个包)=url(网页地址)+lib() 第一部分:protocol:/ ...
- 梯度下降算法(Gradient Descent)
近期在搞论文,须要用梯度下降算法求解,所以又一次整理分享在这里. 主要包含梯度介绍.公式求导.学习速率选择.代码实现. 梯度下降的性质: 1.求得的解和选取的初始点有关 2.能够保证找到局部最优解,由 ...
- 你知道Windows和WordPress上帝模式吗?
一.Windows 上帝模式 这个玩意出来很久很久了,估计不用多说,知道的同学还是挺多的,不知道的也只要百度一下,你就知道了. 方法很简单,在 Windows 系统任何地方新建一个文件夹,如下命名即可 ...
- Selenium+Java元素定位之一
通过id进行定位 driver.findElement(By.id("kw")).sendKeys("博客园"); 通过name进行定位 driver.find ...
- SQL CASE 多条件用法
Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN ...