zoukankan      html  css  js  c++  java
  • 「HDU 1150」「UVA 1194」 Machine Schedule

    Description

    YkG2ZQ.png

    Hint

    • (1le n, mle 100)
    • (1le kle 10^3)
    • (0le a_i < n, 0le b_i<m)

    Solution

    (A)(n) 个模式视作 (n)(x) 部的点, 把 (B)(m) 个模式视作 (m)(y) 部的点,把一个任务的属性 ((a_i, b_i)) 抽象成一条连接 (x) 部的第 (a_i) 个点,(y) 部的第 (b_i) 个点的边。

    于是构成了一张 二分图

    本题有一个要素,即每个任务要么在 (A) 上的 (a_i) 模式执行,要么在 (B) 上的 (b_i) 模式上执行。

    转化成二分图的语言: 一条边的两个端点至少选择其中一个

    题目又要求重启尽可能少,于是就要 选择尽量少的点

    显然就是 二分图最小点覆盖 问题,可以用匈牙利算法在 (O(nm)) 的时间内通过本题。

    注意,初始状态为模式 0,注意不用算进去。

    Hint

    /*
     * Author : _Wallace_
     * Source : https://www.cnblogs.com/-Wallace-/
     * Problem : HDU 1150 UVA 1194 Machine Schedule
     */
    #include <cstdio>
    #include <vector>
    #include <cstring>
    
    using namespace std;
    const int N = 105;
    
    int n, m, k;
    vector<int> G[N];
    
    int match[N], vis[N];
    bool Dfs(int x, int t) {
    	if (vis[x] == t) return false;
    	vis[x] = t;
    	for (auto y : G[x]) if (match[y] == -1 || Dfs(match[y], t))
    		return match[y] = x, true;
    	return false;
    }
    
    void solve() {
    	memset(vis, 0, sizeof vis);
    	memset(match, -1, sizeof match);
    	for (register int i = 0; i < n; i++)
    		G[i].clear();
    	for (register int i = 0, a, b; i < k; i++) {
    		scanf("%d%d%d", &i, &a, &b);
    		G[a].push_back(b);
    	}
    	
    	int ans = 0;
    	for (register int i = 1; i < n; i++)
    		ans += int(Dfs(i, i));
    	printf("%d
    ", ans);
    }
    
    signed main() {
    	while (scanf("%d", &n) != EOF && n)
    		scanf("%d%d", &m, &k), solve();
    	return 0;
    }
    
  • 相关阅读:
    区分DPI、分辨率(PPI)、图像的物理大小、像素宽度
    生成缩略图方法
    C#中调用Windows API的要点 .
    改变变量触发事件
    窗体异步示例
    Scroll滚动后发生的改变
    绘制不同颜色的文本图片
    字符串绘图片
    c#生成缩略图
    衔接UI线程和管理后台工作线程的类(多线程、异步调用)
  • 原文地址:https://www.cnblogs.com/-Wallace-/p/12833573.html
Copyright © 2011-2022 走看看