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
  • 相关阅读:
    双系统下,Windows如何正确删除Linux系统
    关于通过adb启动Activity、activity、service以及发送broadcast的命令
    Eclipse常用快捷键集合
    关于“学习Linux用什么系统”的解答
    关于设置android:imeOptions属性无效的解决办法
    Android XML文件布局各个属性详解
    Android开发:文本控件详解——EditText(一)基本属性
    Android开发:UI相关(一)自定义样式资源
    Android开发:文本控件详解——TextView(一)基本属性
    Android开发:Android Studio开发环境配置
  • 原文地址:https://www.cnblogs.com/zafuacm/p/3216355.html
Copyright © 2011-2022 走看看