• HDU-1281 棋盘游戏


    行列二分匹配。位于重要点的判断,删边后再判断最大匹配是否变小。

    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <fstream>
    #include <iostream>
    
    #define rep(i, l, r) for(int i=l; i<=r; i++)
    #define down(i, l, r) for(int i=l; i>=r; i--)
    #define N 123
    #define MAX 1<<30
    
    using namespace std;
    int read()
    {
    	int x=0, f=1; char ch=getchar();
    	while (ch<'0' || ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
    	while (ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
    	return x*f;
    }
    
    struct node{int y, n; bool b;} e[N*N]; int fir[N*2], en; 
    int n, m, c, k[N], kans[N], ans, ans2, t;
    bool b[N];
    
    inline void Add(int x, int y)
    {
    	en++, e[en].y=y, e[en].b=1, e[en].n=fir[x], fir[x]=en;
    }
    
    bool Find(int x)
    {
    	int o=fir[x], y=e[o].y;
    	while (o)
    	{
    		if (e[o].b && !b[y])
    		{ 
    			b[y]=1; if (!k[y] || Find(k[y])) { k[y]=x; return true; } 
    		}
    		o=e[o].n, y=e[o].y;
    	}
    	return false;
    }
    
    inline int Check()
    {
    	rep(i, 1, n) k[i]=0; int a=0;
    	rep(i, 1, m) { rep(j, 1, n) b[j]=0; if (Find(i+N)) a++; }
    	return a;
    }
    
    int main()
    {
    	while(~scanf("%d%d%d", &n, &m, &c))
    	{
    		t++; ans=ans2=0;
    		en=0; rep(i, 1, m) fir[i+N]=0; 
    		rep(i, 1, c) { int x=read(), y=read(); Add(y+N, x); }
    		ans = Check();
    		rep(i, 1, n) kans[i]=k[i];
    		rep(i, 1, n) if (kans[i])
    		{
    			int o=fir[kans[i]]; while (e[o].y != i) o=e[o].n;
    			e[o].b=0;
    			if (Check() != ans) ans2++;
    			e[o].b=1;
    		}
    		printf("Board %d have %d important blanks for %d chessmen.
    ", t, ans2, ans);
    	}
    	return 0;
    }
  • 相关阅读:
    windows下 php5.3如何连接mssql
    ie 兼容性
    windows 版Tomcat 7.0的配置
    数据库备份
    PHP实现通过经纬度计算距离
    linux内核升级(ubuntu12.04从3.13.0升级到3.4.0 )
    详解Linux Initrd
    基于stm32的can总线彻底研究
    CAN控制器-配置过滤器
    recv send 阻塞和非阻塞
  • 原文地址:https://www.cnblogs.com/NanoApe/p/4342787.html
Copyright © 2020-2023  润新知