zoukankan      html  css  js  c++  java
  • POJ3041 Asteroids(二分图最大匹配)

    题目链接

    分析:

    暂略。

    AC代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <string>
    #include <map>
    
    using namespace std;
    
    const int maxn = 510;
    int n;
    bool G[maxn][maxn];
    int linker[maxn];
    bool used[maxn];
    
    bool dfs(int u) {
        for(int v=0; v<n; v++)
        if(G[u][v] && !used[v]) {
            used[v] = true;
            if(linker[v] == -1 || dfs(linker[v])) {
                linker[v] = u;
                return true;
            }
        }
        return false;
    }
    
    int hungary() {
        int res = 0;
    
        memset(linker, -1, sizeof(linker));
    
        for(int u=0; u<n; u++) {
            memset(used, 0, sizeof(used));
            if(dfs(u)) res++;
        }
    
        return res;
    }
    
    int main() {
        int k, r, c;
    
       // freopen("my.txt", "r", stdin);
    
        while(scanf("%d%d", &n, &k) == 2) {
            memset(G, false, sizeof(G));
    
            for(int i=0; i<k; i++) {
                scanf("%d%d", &r, &c);
                G[--r][--c] = true;
            }
    
            int ans = hungary();
    
            printf("%d
    ", ans);
        }
    
        return 0;
    }
  • 相关阅读:
    a冲刺总结随笔
    a版本冲刺第十天
    a版本冲刺第九天
    a版本冲刺第八天
    a版本冲刺第七天
    a版本冲刺第六天
    a版本冲刺第五天
    BETA 版冲刺前准备
    Alpha事后诸葛会议
    Alpha答辩总结
  • 原文地址:https://www.cnblogs.com/tanhehe/p/3172418.html
Copyright © 2011-2022 走看看