poj 1274The Perfect Stall 二分匹配模板水题

#include<iostream>

#include<cstdio>

#include<cstring>

using namespace std;

const int maxn = 210;

int match[maxn];

int line[maxn][maxn];

int vis[maxn];

int N , M;

int find(int start)

{

for(int i = 1;i <= M;i++)

{

if(!vis[i]&&line[start][i])

{

vis[i] = 1;

if(match[i] == -1 || find(match[i]))

{

match[i] = start;

return 1;

}

}

}

return 0;

}

void Match()

{

memset(match, -1 , sizeof(match));

int ans=0;

for(int i = 1;i <= N;i++)

{

memset(vis,0,sizeof(vis));

if(find(i))

ans++;

}

printf("%d\n",ans);

}

int main()

{

while(scanf("%d%d" , &N , &M)!=EOF)

{

memset(line,0,sizeof(line));

for(int i = 1;i <= N;i++)

{

int num;

scanf("%d" , &num);

while(num--)

{

int  v;

scanf("%d", &v);

line[i][v]=1;

}

}

Match();

}

return 0;

}

时间: 2024-08-04 16:56:52

poj 1274The Perfect Stall 二分匹配模板水题的相关文章

poj 1274The Perfect Stall

第一次接触二分图匹配. 这题是一个匈牙利算法的模板题直接套就行. 题意是  给你奶牛和谷仓的个数a和b,接下来a行是奶牛喜欢去的谷仓.第一个是谷仓个数,接下来是谷仓编号. 这里我们把行当奶牛,列当谷仓. 在套模板..ok: #include<Stdio.h> #include<string.h> int map[1005][1005]; int a,b,link[1005],use[1005]; int dfs(int cap) { int i,j; for(i=1;i<=b

POJ 1274--The Perfect Stall【二分图 &amp;&amp; 最大匹配数 &amp;&amp; 水题】

The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20795   Accepted: 9386 Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering pr

POJ 1274-The Perfect Stall(二分图_最大匹配)

The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19272   Accepted: 8737 Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering pr

poj1469 COURSES 二分匹配模板水题

#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn = 310; int match[maxn]; int line[maxn][maxn]; int vis[maxn]; int N , P; int find(int start) { for(int i = 1;i <= N;i++) { if(!vis[i]&&li

poj 1274 The Perfect Stall (二分匹配)

The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17768   Accepted: 8104 Description Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering pr

POJ 2545+2591+2247+1338简单水题

[题意简述]:就是有这样的一个序列,就拿当p1 = 2,p2 = 3, p3 = 5,来举例,由这三个数为基准组成的序列是: 2,3,4,5,6,8,9,10,12--现在给你这个序列数组的下标,让你求得这个数组中,这个下标里的数是多少. [分析]:2,3,4,5,6,8,9,10,12--这个序列式由2,3,5这三个数生成的,具体如何生成,就是: 详见代码: 这里以POJ2545为例: //弄清其中的逻辑关系,可以从最简单的2,3,5试着做起! #include<iostream> #inc

POJ 3069 Saruman&#39;s Army(水题,简单的贪心)

[题意简述]:在一条直线上有N个点,每个点的位置分别是Xi,现从这N个点中选择若干个点给他们加上标记.使得,对每个点而言,在其距离为R的范围内都有带有标记的店,问   至少   要有几个被标记的点. [分析]:我们可以对这个点的序列简单的排序,按照从左到右,从小到大,然后对于最左边的这一个点,我们计算从这个点开始加上这个距离R可以到达的最远的但又小于这个距离R的点是哪一个,然后以这个点为基准,重复上述的过程,最终计算出点的个数. 详见代码: //244K 63Ms #include<iostre

POJ 2081 Recaman&#39;s Sequence(水题)

[题意简述]:这个题目描述很短,也很简单.不再赘述. [分析]:只需再加一个判别这个数是否出现的数组即可,注意这个数组的范围! // 3388K 0Ms #include<iostream> using namespace std; #define Max 500001 int a[Max]; bool b[10000000] = {false}; // b的数据范围是可以试出来的- void init() { a[0] = 0; b[0] = true; for(int m = 1;m<

Goldbach&#39;s Conjecture POJ - 2262 线性欧拉筛水题 哥德巴赫猜想

题意 哥德巴赫猜想:任一大于2的数都可以分为两个质数之和 给一个n 分成两个质数之和 线行筛打表即可 可以拿一个数组当桶标记一下a[i]  i这个数是不是素数  在线性筛后面加个装桶循环即可 #include<cstdio> #include<cstring> using namespace std; bool Is_Primes[1000005]; int Primes[1000005]; int cnt; void Prime(int n){ cnt=0; memset(Is_