zoukankan      html  css  js  c++  java
  • [poj 1325]Machine Schedule

    Machine Schedule
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 15388   Accepted: 6605

    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

    题目大意
    有两台机器,每个机器有多种模式。给定一些任务,每个任务可由机器A的指定一种模式完成,或由机器B的指定一种模式完成。求问更换最少的机器次数。

    思路
    最小点覆盖
    最小点覆盖等于最大匹配数

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cmath>
     4 #include<cstdio>
     5 #include<cstring>
     6 #include<cstdlib>
     7 
     8 using namespace std;
     9 
    10 int read()
    11 {
    12     int x=0,f=1;
    13     char ch=getchar();    
    14     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    15     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
    16     return x*f;
    17 }
    18 int n,m,k,tmp1,tmp2,con[110];
    19 bool g[110][110],vis[110];
    20 bool dfs(int p)
    21 {
    22     for(int j=1;j<m;j++)
    23     {
    24         if(g[p][j] && !vis[j])
    25         {
    26             vis[j]=1;
    27             if(con[j]==0 || dfs(con[j]))
    28             {
    29                 con[j]=p;
    30                 return true;
    31             }
    32         }
    33     }
    34     return false;
    35 }
    36 void hungary()
    37 {
    38     int ans=0;
    39     memset(con,0,sizeof(con));
    40     for(int i=1;i<n;i++)
    41     {
    42         memset(vis,0,sizeof(vis));
    43         if(dfs(i))ans++;
    44     }
    45     printf("%d
    ",ans);
    46 }
    47 int main()
    48 {
    49     while(scanf("%d",&n) && n!=0)
    50     {
    51         m=read();k=read();
    52         memset(g,0,sizeof(g));
    53         for(int i=0;i<k;i++)
    54         {
    55             tmp1=read();
    56             tmp1=read();tmp2=read();
    57             if(tmp1==0 || tmp2==0)continue;
    58             g[tmp1][tmp2]=1;
    59         }
    60         hungary();
    61     }
    62     system("pause");
    63     return 0;
    64 }
    View Code
  • 相关阅读:
    Httpd服务入门知识-Httpd服务常见配置案例之显示服务器版本信息
    破解CentOS7的root及加密grub修复实战
    Httpd服务入门知识-Httpd服务安装
    Httpd服务入门知识-http协议版本,工作机制及http服务器应用扫盲篇
    Linux操作系统-CentOS7启动流程和服务管理
    Socket网络编程-IO各种概念及多路复用
    Socket网络编程-SocketServer
    Socket网络编程-UDP编程
    Socket网络编程-TCP编程
    Linux操作系统内核编译之NTFS文件系统模块支持案例
  • 原文地址:https://www.cnblogs.com/taojy/p/7192872.html
Copyright © 2011-2022 走看看