zoukankan      html  css  js  c++  java
  • hdu1150最小点集覆盖

    连着做两道最小点集覆盖的题,直接拿上一题代码改的,都没改几句。。

    /*
     * hdu1150/win.cpp
     * Created on: 2012-8-14
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    
    const int MAXN = 210;
    int N, M, mymatch[MAXN];
    bool visited[MAXN], mymap[MAXN][MAXN];
    
    bool buildgraph() {
        int t, K, a, b;
        scanf("%d", &N);
        if(N == 0) {
            return false;
        }
        scanf("%d%d", &M, &K);
        memset(mymap, false, sizeof(mymap));
    
        for(int i = 0; i < K; i++) {
            scanf("%d%d%d", &t, &a, &b);
            if(a != 0 && b != 0) {
                mymap[a - 1][b - 1] = true;
            }
        }
        return true;
    }
    bool dfs(int k) {
        int t;
        for (int i = 0; i < M; i++) {
            if (mymap[k][i] && !visited[i]) {
                visited[i] = true; t = mymatch[i]; mymatch[i] = k;
                if (t == -1 || dfs(t)) {
                    return true;
                }
                mymatch[i] = t;
            }
        }
        return false;
    }
    int hungary () {
        memset(mymatch, -1, sizeof(mymatch));
        int ans = 0;
        for (int i = 0; i < N; i++) {
            memset(visited, false, sizeof(visited));
            if (dfs(i)) {
                ans++;
            }
        }
        return ans;
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        while(buildgraph()) {
            printf("%d\n", hungary());
        }
        return 0;
    }
  • 相关阅读:
    彻底弄懂最短路径问题[转]
    activiti任务TASK
    linux查看磁盘空间
    Introduction to the POM
    【转】10 个迅速提升你 Git 水平的提示
    macbook安装mysql
    java并发编程之美-笔记
    springboot2精髓读书笔记
    java多线程
    实战JAVA虚拟机笔记
  • 原文地址:https://www.cnblogs.com/moonbay/p/2638837.html
Copyright © 2011-2022 走看看