zoukankan      html  css  js  c++  java
  • 二分图匹配

    死了,还有10天

    十分模板的匈牙利(为什么大家都写hungary()???)

    难道不应该是xiongyali()吗

    hdu2063

    模板题。背景还蛮有意思的。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    inline void in(int &p,char c=getchar())
    {
    	while(c<'0' or c>'9')
    		c=getchar();
    	p=0;
    	while(c>='0' and c<='9')
    		p=p*10+c-'0',c=getchar();
    }
    int k,girl,boy;
    vector <int> w[501];
    int ans;
    bool incp[501];
    int match[501];//match[boy]=girl
    bool findpath(int x)
    {
    	for(unsigned int i=0;i<w[x].size();i++)
    	{
    		if(!incp[w[x][i]])
    		{
    			incp[w[x][i]]=1;
    			if(!match[w[x][i]] or findpath(match[w[x][i]]))
    			{
    				match[w[x][i]]=x;
    				return 1;
    			}
    		}
    	}
    	return 0;
    }
    void hungary()
    {
    	for(int i=1;i<=girl;i++)
    	{
    		memset(incp,0,sizeof(incp));
    		if(findpath(i))
    			ans++;
    	}
    }
    int main()
    {
    	while(scanf("%d",&k) and k)
    	{
    		in(girl);in(boy);
    		for(int i=1;i<=girl;i++)
    			w[i].clear();
    		memset(match,0,sizeof(match));
    		ans=0;
    		for(int i=0;i<k;i++)
    		{
    			int x,y;
    			in(x);in(y);
    			w[x].push_back(y);
    		}
    		hungary();
    		cout<<ans<<endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    说说移动端web开发中的点击穿透问题
    将博客搬至CSDN
    IIS(4)
    IIS(2)
    IIS(3)
    IIS(1)
    链表
    常用到的关键字
    进程与线程
    文件系统的原理
  • 原文地址:https://www.cnblogs.com/syhien/p/7768641.html
Copyright © 2011-2022 走看看