• hdu1498最小点集覆盖


    对于每一种颜色的气球都建一次图求最大匹配即可。

    /*
     * hdu1498/win.cpp
     * Created on: 2012-8-16
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    const int MAXN = 200;
    vector<int> mymap[MAXN];
    int N, M, mymatch[MAXN];
    bool visited[MAXN];
    int matrixs[MAXN][MAXN];
    void init() {
        for(int i = 0; i < N; i++) {
            mymap[i].clear();
        }
    }
    bool dfs(int k) {
        int t, I;
        for(int i = 0; i < (int)mymap[k].size(); i++) {
            I = mymap[k][i];
            if(!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;
    }
    bool buildgraph(int k) {
        init();
        for (int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                if(matrixs[i][j] == k) {
                    mymap[i].push_back(j);
                }
            }
        }
        return true;
    }
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        int k;
        bool flags[52];
        char str[500];
        while(scanf("%d%d", &N, &k) == 2) {
            if(N == 0 && k == 0) {
                break;
            }
            for(int i = 0; i < N; i++) {
                for(int j = 0; j < N; j++) {
                    scanf("%d", &matrixs[i][j]);
                }
            }
            for(int i = 1; i <= 50; i++) {
                buildgraph(i);
                flags[i] = (hungary() <= k);
            }
            char *p = str;
            for(int i = 1; i <= 50; i++) {
                if(!flags[i]) {
                    p += sprintf(p, "%d ", i);
                }
            }
            if(p == str) {
                puts("-1");
            }else {
                int len = strlen(str);
                str[len - 1] = 0;
                puts(str);
            }
        }
        return 0;
    }
  • 相关阅读:
    Entity Framework Code First使用DbContext查询
    Entity Framework Code First执行SQL语句、视图及存储过程
    Entity Framework Code First关系映射约定
    Entity Framework Code First属性映射约定
    Entity Framework Code First数据库连接
    EF Power Tools参数不正确的解决方法
    EF Code First Migrations数据库迁移
    前端Js框架汇总【转】
    浅谈Hybrid技术的设计与实现【转】
    用于HTML5移动开发的10大移动APP开发框架【转】
  • 原文地址:https://www.cnblogs.com/moonbay/p/2642341.html
Copyright © 2020-2023  润新知