zoukankan      html  css  js  c++  java
  • hdu1150——最小点覆盖

    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. 

    InputThe 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. 
    OutputThe 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


    大意:两个机器,分别有N个和M个模式,K个工作,每个工作可以用第一个机器的某个模式完成或者用第二个机器的某个模式完成。每次机器切换模式都需要重新启动。
    问最少重启几次机器。
    这是一个裸的最小点覆盖,还是求一个图中与每条边相邻的最小点集。最大匹配=最小点覆盖
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<ctime>
     5 #include<cstdlib>
     6 #include<algorithm>
     7 #include<cmath>
     8 #include<string>
     9 using namespace std;
    10 int read(){
    11     int xx=0,ff=1;char ch=getchar();
    12     while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    13     while(ch>='0'&&ch<='9'){xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
    14     return xx*ff;
    15 }
    16 const int maxn=210;
    17 int lin[maxn],len,N,M,K,ans;
    18 struct edge{
    19     int y,next;
    20 }e[1010];
    21 inline void insert(int xx,int yy){
    22     e[++len].next=lin[xx];
    23     e[len].y=yy;
    24     lin[xx]=len;
    25 }
    26 int tim,pretim,match[maxn],vis[maxn];
    27 bool hun(int x){
    28     for(int i=lin[x];i;i=e[i].next)
    29         if(vis[e[i].y]<=pretim){
    30             vis[e[i].y]=++tim;
    31             if(match[e[i].y]==0||hun(match[e[i].y])){
    32                 match[e[i].y]=x;
    33                 match[x]=e[i].y;
    34                 return 1;
    35             }
    36         }
    37     return 0;
    38 }
    39 int main(){
    40     //freopen("in","r",stdin);
    41     //freopen("out","w",stdout);
    42     while(1){
    43         N=read();
    44         if(!N)
    45             break;
    46         M=read(),K=read();
    47         memset(lin,0,sizeof(lin));len=0;
    48         for(int i=1;i<=K;i++){
    49             read();
    50             int t1=read(),t2=read();
    51             insert(t1,t2+N);
    52         }
    53         ans=0;tim=0;pretim=0;
    54         memset(match,0,sizeof(match));
    55         memset(vis,0,sizeof(vis));
    56         for(int i=1;i<=N+M;i++)
    57             if(!match[i]){
    58                 pretim=tim;
    59                 vis[i]=++tim;
    60                 if(hun(i))
    61                     ans++;
    62             }
    63         printf("%d
    ",ans);
    64     }
    65     return 0;
    66 }
     
  • 相关阅读:
    Linux查看进程是否存在及启动或重启
    Leetcode 31.下一个排列 tag数组
    Leetccode 27.移除元素 tag数组
    Leetcode 24:两两交换链表中的节点
    当代90后的焦虑
    典型java面试题
    TD编译环境变量说明
    ubuntu20.04安装TD工具后编译错误
    ssh免密登录在Linux服务器之间的设置
    ubuntu20.04导航栏放到底部
  • 原文地址:https://www.cnblogs.com/lzhAFO/p/8074741.html
Copyright © 2011-2022 走看看