zoukankan      html  css  js  c++  java
  • HDU1150--Machine Schedule

    Machine Schedule
    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 4189 Accepted Submission(s): 2042


    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

    机器转换为路径,

    最小路径覆盖=最大匹配

     1 #include<cstdio>
     2 #include<cmath>
     3 #include<iostream>
     4 #include<algorithm>
     5 #include<cstring>
     6 using namespace std;
     7 
     8 int n;
     9 int cx[1001],cy[1001];
    10 int mk[1001];
    11 int link[1001][1001];
    12 
    13 void init()
    14 {
    15     memset(cx,0xff,sizeof(cx));
    16     memset(cy,0xff,sizeof(cy));
    17     memset(link,0,sizeof(link));
    18 }
    19 
    20 int path(int u)
    21 {
    22     int v;
    23     for(v=0;v<n;v++)
    24     {
    25         if(!mk[v]&&link[u][v])
    26         {
    27             mk[v]=1;
    28             if(cy[v]==-1||path(cy[v]))
    29             {
    30                 cy[v]=u;
    31                 cx[u]=v;
    32                 return 1;
    33             }
    34         }
    35     }
    36     return 0;
    37 }
    38 
    39 int find()
    40 {
    41     int sum=0;
    42     int i;
    43     for(i=0;i<n;i++)
    44     {
    45         if(cx[i]==-1)
    46         {
    47             memset(mk,0,sizeof(mk));
    48             sum+=path(i);
    49         }
    50     }
    51     return sum;
    52 }
    53 
    54 int main()
    55 {
    56     while(scanf("%d",&n)!=EOF&&n!=0)
    57     {
    58         init();
    59         int i;
    60         for(i=0;i<n;i++)
    61         {
    62             int s,e,num;
    63             scanf("%d: (%d)",&s,&num);
    64             while(num--)
    65             {
    66                 scanf("%d",&e);
    67                 link[s][e]=1;
    68             }
    69         }
    70         int ans=find();
    71         printf("%d
    ",n-ans/2);
    72     }
    73     return 0;
    74 }
    View Code
  • 相关阅读:
    残疾流浪歌手的令人陶醉的声音
    关于浏览器参数的获取
    项目开发文档模板
    scoped_ptr源码
    从逗号分隔的字符串中删除某个子串的js函数
    合并两个数组的js函数
    comutil.h移值(_com_error,_bstr_t,_variant_t类的移值)
    判断两个对象是否相等的js函数
    托管可执行文件的结构(The Structure of a Managed Executable File)
    访问cookie的js函数
  • 原文地址:https://www.cnblogs.com/zafuacm/p/3216355.html
Copyright © 2011-2022 走看看