zoukankan      html  css  js  c++  java
  • Machine Schedule

    Machine Schedule

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 157 Accepted Submission(s): 94
     
    Problem Description
    As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type of schedule desired. Here we consider a 2-machine scheduling problem.

    There are two machines A and B. Machine A has n kinds of working modes, which is called mode_0, mode_1, …, mode_n-1, likewise machine B has m kinds of working modes, mode_0, mode_1, … , mode_m-1. At the beginning they are both work at mode_0.

    For k jobs given, each of them can be processed in either one of the two machines in particular mode. For example, job 0 can either be processed in machine A at mode_3 or in machine B at mode_4, job 1 can either be processed in machine A at mode_2 or in machine B at mode_4, and so on. Thus, for job i, the constraint can be represent as a triple (i, x, y), which means it can be processed either in machine A at mode_x, or in machine B at mode_y.

    Obviously, to accomplish all the jobs, we need to change the machine's working mode from time to time, but unfortunately, the machine's working mode can only be changed by restarting it manually. By changing the sequence of the jobs and assigning each job to a suitable machine, please write a program to minimize the times of restarting machines.
     
    Input
    The input file for this program consists of several configurations. The first line of one configuration contains three positive integers: n, m (n, m < 100) and k (k < 1000). The following k lines give the constrains of the k jobs, each line is a triple: i, x, y.

    The input will be terminated by a line containing a single zero.
     
    Output
    The output should be one integer per line, which means the minimal times of restarting machine.
     
    Sample Input
    5 5 10
    0 1 1
    1 1 2
    2 1 3
    3 1 4
    4 2 1
    5 2 2
    6 2 3
    7 2 4
    8 3 3
    9 4 3
    0
     
    Sample Output
    3
     
     
    Source
    Asia 2002, Beijing (Mainland China)
     
    Recommend
    Ignatius.L
     
    /*
    给出k个程序,每个程序表示为x,y表示这个程序可以在A机器上的x模式下运行,也可以在B机器上的y模式下运行
    但是AB每次换模式的时候都会重启一次,问完成k个操作的时候AB最少的重启次数是多少,可以将k此操作看成是二分图,
    A B分别属于两个集合,也就是求最小覆盖的点数,转化成二分图的最大匹配就可以了。
    */
    #include<bits/stdc++.h>
    #define N 110
    using namespace std;
    int n,m,k;
    int mapn[N][N];
    int linker[N];//用来标记i点的匹配点是谁
    bool used[N];//用来表示点i是不是被用过了
    int op,x,y;
    bool dfs(int u){//找能不能通过分手来解决找对象的问题
        for(int v=0;v<m;v++){//找匹配点
            if(mapn[u][v]&&!used[v]){
                used[v]=true;
                if(linker[v]==-1||dfs(linker[v])){//这个点没用过并且可以当作对象
                    linker[v]=u;
                    return true;
                }
            }
        }
        return false;
    }
    int hungry(){
        int res=0;
        memset(linker,-1,sizeof linker);
        for(int u=0;u<n;u++){
            memset(used,false,sizeof used);
            if(dfs(u))//这个点可以找到对象
                res++;
        }
        return res;
    }
    void init(){
        memset(mapn,0,sizeof mapn);
    }
    int main(){
        //freopen("in.txt","r",stdin);
        while(scanf("%d",&n)!=EOF&&n){
            init();
            scanf("%d%d",&m,&k);
            for(int i=0;i<k;i++){
                scanf("%d%d%d",&op,&x,&y);
                if(x>0&&y>0)
                    mapn[x][y]=1;
            }//建图
            int cur=hungry();
            printf("%d
    ",cur);
        }
        return 0;
    }
  • 相关阅读:
    分页查询
    web 开发中 405报错
    html 中input标签的name属性
    怎么样利用debug
    bzoj 1314: River过河 优先队列
    bzoj 4004: [JLOI2015]装备购买 拟阵 && 高消
    bzoj 1133: [POI2009]Kon dp
    bzoj 4127: Abs 树链剖分
    bzoj 2406: 矩阵 上下界网络流判定
    再写FFT模板
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/6200735.html
Copyright © 2011-2022 走看看