zoukankan      html  css  js  c++  java
  • P2071 座位安排(二分图)

    Miku

    既然是二分图匹配的模板

    为什么不和模板一样是绿的

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    struct b{
    	int to;
    	int ne;
    }e[16001];
    int head[4001];
    int p;
    int n;
    int x,y;
    int match[4001];
    int vis[4001];
    int cnt;
    void add(int f,int to){
    	p++;
    	e[p].to=to;
    	e[p].ne=head[f];
    	head[f]=p;
    }
    bool find(int now){
    	for(int v=head[now];v;v=e[v].ne){
    		int i=e[v].to;
    			if(!vis[i]){
    				vis[i]=1;
    				if((match[i]==0)||find(match[i])){
    					match[i]=now;
    					return 1;
    				}
    			}
    	}
    	return 0;
    }
    int main(){
    	scanf("%d",&n);
    	for(int i=1;i<=n*2;++i){
    		scanf("%d%d",&x,&y);
    		add(i,y*2);
    		add(i,y*2-1);
    		add(i,x*2);
    		add(i,x*2-1);
    	}
    	for(int i=1;i<=n*2;++i){
    		memset(vis,0,sizeof(vis));
    		if(find(i))
    		cnt++;
    	}
    	cout<<cnt;
    	return 0;
    }
    
  • 相关阅读:
    php函数
    php循环语句(二)
    php循环语句(一)
    php魔术常量
    php超级全局变量
    php数组函数
    php数组
    php条件语句(二)
    php条件语句(一)
    shell 中的判断
  • 原文地址:https://www.cnblogs.com/For-Miku/p/13455677.html
Copyright © 2011-2022 走看看