首页 > 其他分享 >hdu-2063 二分图

hdu-2063 二分图

时间:2023-03-03 13:07:13浏览次数:49  
标签:二分 hdu include int 过山车 partner 2063 match 1000

http://acm.hdu.edu.cn/showproblem.php?pid=2063

过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11731    Accepted Submission(s): 5151


Problem Description RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了。可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐。但是,每个女孩都有各自的想法,举个例子把,Rabbit只愿意和XHD或PQK做partner,Grass只愿意和linle或LL做partner,PrincessSnow愿意和水域浪子或伪酷儿做partner。考虑到经费问题,boss刘决定只让找到partner的人去坐过山车,其他的人,嘿嘿,就站在下面看着吧。聪明的Acmer,你可以帮忙算算最多有多少对组合可以坐上过山车吗?  
Input 输入数据的第一行是三个整数K , M , N,分别表示可能的组合数目,女生的人数,男生的人数。0<K<=1000
1<=N 和M<=500.接下来的K行,每行有两个数,分别表示女生Ai愿意和男生Bj做partner。最后一个0结束输入。  
Output 对于每组数据,输出一个整数,表示可以坐上过山车的最多组合数。  
Sample Input 6 3 3 1 1 1 2 1 3 2 1 2 3 3 1 0  
Sample Output 3  

一天不AC 智商不如猪

今天学的二分图 ac了这个很久之前就见到的题


#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string.h>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

int n,m,k;
int p[1000][1000];
int book[1000];
int match[1000];
int t,tt;
int a,b;

int dfs(int u)
{
	int i;
	for(i=1;i<=k;i++)
	{
		if(book[i]==0 && p[u][i] == 1)
		{
			book[i] = 1;
			if(match[i] == 0 || dfs(match[i]))
			{
				match[i]=u;
				return 1;
			}
		}
	}
	return 0;
}


int main()
{
	while (cin>>n && n!=0)
	{
		cin>>m>>k;

		int ans = 0;
		memset(match,0,sizeof(match));
		memset(p,0,sizeof(p));

		for(int i=1;i<=n;i++)
		{
			cin>>a>>b;
			p[a][b] = 1;
		}

		for(int i=1;i<=m;i++)
		{
			memset(book,0,sizeof(book));
			if( dfs(i) )
				ans ++;
		}
		cout<<ans<<endl;
	}

	return 0;
}



标签:二分,hdu,include,int,过山车,partner,2063,match,1000
From: https://blog.51cto.com/u_15990681/6098459

相关文章

  • hdu-1010
    简单深搜剪枝http://acm.hdu.edu.cn/showproblem.php?pid=1010#include<iostream>#include<algorithm>#include<set>#include<map>#include<string.h>#inc......
  • hdu-1301
    模板题#include<iostream>#defineINF999999usingnamespacestd;intmap[30][30],dis[30],v[30];intprim(intn){inti,j,k,min,sum=0;for(i=1;i<=n......
  • hdu-1495
    bfs六种状态 #include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#include<ctype.h>#include<algorithm>#include<vector>#include<st......
  • hdu-2614
    取得第一个是第一个任务,时间0,接着进行下一个任务。#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#include<ctype.h>#include<alg......
  • hdu-1195
    http://acm.hdu.edu.cn/showproblem.php?pid=1195bfs加1减1交换,三个方式#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#includ......
  • hdu-1016
    约瑟夫换问题http://acm.hdu.edu.cn/showproblem.php?pid=1016#include<stdio.h>#include<stdlib.h>#include<algorithm>#include<string.h>intn,cas=1,vi......
  • hdu-1238
    http://acm.hdu.edu.cn/showproblem.php?pid=1238SubstringsTimeLimit:2000/1000MS(Java/Others)    MemoryLimit:65536/32768K(Java/Others)TotalS......
  • hdu-1515
    dfs 题意:给你两个字符串,问:第一个字符串按入栈出栈规则,能否达到第二个字符串,输出所有的方法,i表示入栈,o表示出栈。用dfs模拟第一个字符串入栈出栈过程:1.当前字符......
  • hdu-1548
    搜索做着做着成最短路径了。。dij本层可以直接到达的层数距离为1否则为无穷大#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#includ......
  • hdu-1253
    http://acm.hdu.edu.cn/showproblem.php?pid=1253这道水题#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#include<......