• POJ 1325 Machine Schedule


    传送门

    HDOJ 1150 Machine ScheduleAcWing 376 机器任务

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <map>
    #include <set>
    #include <algorithm>
    
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> p;
    const double pi(acos(-1));
    const int inf(0x3f3f3f3f);
    const int mod(1e9 + 7);
    const int maxn(1e2 + 10);
    bool g[maxn][maxn], vis[maxn];
    int n, m, k, match[maxn];
    
    template<typename T>
    inline const T read()
    {
        T 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 << 3) + (x << 1) + ch - '0';
            ch = getchar();
        }
        return x * f;
    }
    
    template<typename T>
    inline void write(T x, bool ln)
    {
        if (x < 0) {
            putchar('-');
            x = -x;
        }
        if (x > 9) write(x / 10, false);
        putchar(x % 10 + '0');
        if (ln) putchar(10);
    }
    
    bool dfs(int u)
    {
        for (int v = 1; v < m; ++v) {
            if (not vis[v] and g[u][v]) {
                vis[v] = true;
                if (not match[v] or dfs(match[v])) {
                    match[v] = u;
                    return true;
                }
            }
        }
        return false;
    }
    
    int hungary()
    {
        int res = 0;
        for (int i = 1; i < n; ++i) {
            memset(vis, false, sizeof vis);
            res += dfs(i);
        }
        return res;
    }
    
    int main()
    {
    #ifdef ONLINE_JUDGE
    #else
        freopen("input.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        while (true) {
            memset(g, false, sizeof g);
            memset(match, 0, sizeof match);
            n = read<int>();
            if (not n) break;
            m = read<int>();
            k = read<int>();
            while (k--) {
                int i = read<int>(), x = read<int>(), y = read<int>();
                if (x and y) {
                    g[x][y] = true;
                }
            }
            write(hungary(), true);
        }
        return 0;
    }
    
  • 相关阅读:
    数据导入
    数据库导入导出命令
    题库
    struts2的配置文件简洁
    修改oralce11g 字符集为ZHS16GBK
    Linux上安装JDK+Tomcat
    Android中adb的使用
    【转】Android获取IP的方法,并可以判断手机是否联网
    Android中R.java没有自动生成问题
    Android中SQLiteOpenHelper的理解
  • 原文地址:https://www.cnblogs.com/singularity2u/p/13938711.html
Copyright © 2020-2023  润新知