zoukankan      html  css  js  c++  java
  • BZOJ 1854 [Scoi2010]游戏

    【题解】

      二分图匹配。

      左边的点是属性值,右边的点是装备。把装备与其对应的两个属性值连边,然后从小到大枚举属性值跑二分图匹配,当无法匹配的时候推出。答案就是当前的属性值-1.

      

    #include<cstdio>
    #include<algorithm>
    #define N 1000010
    #define rg register
    using namespace std;
    int n,m,E,tot,ans,T,last[N],v[N],from[N];
    struct edge{
    	int to,pre;
    }e[N<<1];
    inline int read(){
    	int k=0,f=1; char c=getchar();
    	while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    	while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
    	return k*f;
    }
    inline void add(int x,int y){e[++tot]=(edge){y,last[x]}; last[x]=tot;}
    bool dfs(int x){
    	for(rg int i=last[x],to;i;i=e[i].pre){
    		if(v[to=e[i].to]!=T){
    			v[to]=T;
    			if((!from[to])||dfs(from[to])){
    				from[to]=x;
    				return 1;
    			}
    		}
    	}
    	return 0;
    }
    int main(){
    	n=read(); T=1;
    	for(rg int i=1,x,y;i<=n;i++) x=read(),y=read(),add(x,i),add(y,i);
    	for(rg int i=1;i<=10000;i++, T++)
    		if(!dfs(i)) return printf("%d
    ",i-1), 0;
    	puts("10000");
    	return 0;
    }
    

      

      

  • 相关阅读:
    os
    虚拟站点配置
    21. Merge Two Sorted Lists
    38. Count and Say
    算法分类的书写模板
    Vue
    问题集、知识点
    [Linux] Linux命令
    回调函数在小程序中的实际应用
    小程序app.onLaunch中获取用户信息,index.onLoad初次载入时取不到值的问题
  • 原文地址:https://www.cnblogs.com/DriverLao/p/8490747.html
Copyright © 2011-2022 走看看