zoukankan      html  css  js  c++  java
  • BNUOJ 5363 Machine Schedule

    Machine Schedule

    Time Limit: 1000ms
    Memory Limit: 32768KB
    This problem will be judged on HDU. Original ID: 1150
    64-bit integer IO format: %I64d      Java class name: Main
     
    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

     
    解题:最小点覆盖!!
     
    由于初始态为0!故含0的不用算了
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <climits>
     7 #include <vector>
     8 #include <queue>
     9 #include <cstdlib>
    10 #include <string>
    11 #include <set>
    12 #include <stack>
    13 #define LL long long
    14 #define pii pair<int,int>
    15 #define INF 0x3f3f3f3f
    16 using namespace std;
    17 const int maxn = 110;
    18 int mp[maxn][maxn],from[maxn],ans,n,m,k;
    19 bool vis[maxn];
    20 bool dfs(int u){
    21     for(int i = 0; i < m; i++){
    22         if(mp[u][i] && !vis[i]){
    23             vis[i] = true;
    24             if(from[i] == -1 || dfs(from[i])){
    25                 from[i] = u;
    26                 return true;
    27             }
    28         }
    29     }
    30     return false;
    31 }
    32 int main() {
    33     int i,u,v,ans;
    34     while(scanf("%d",&n),n){
    35         scanf("%d %d",&m,&k);
    36         memset(mp,0,sizeof(mp));
    37         memset(from,-1,sizeof(from));
    38         while(k--){
    39             scanf("%d %d %d",&i,&u,&v);
    40             if(u && v) mp[u][v] = 1;
    41         }
    42         for(ans = i = 0; i < n; i++){
    43             memset(vis,false,sizeof(vis));
    44             if(dfs(i)) ans++;
    45         }
    46         printf("%d
    ",ans);
    47     }
    48     return 0;
    49 }
    View Code
  • 相关阅读:
    微软面试智力题
    苹果下好用的中文输入法
    Programming on Mac OS X Learn ObjectC Serials (1)
    Mac OS X Glut build instructions
    window.opener 的用法
    jboss5.1.0.GA :org.apache.tomcat.jni.Error
    分账模式助力电子商务
    SON JAVA 使用方法
    网站功能用语
    如何在spring框架中解决多数据源的问题
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/3907179.html
Copyright © 2011-2022 走看看