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

    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.
    题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数.

    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做,值得注意的一点是开始状态为0,所以那些模式为0的边不要加

    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define inf 0x7f7f7f
    using namespace std;
    typedef long long ll;
    typedef unsigned int ui;
    typedef unsigned long long ull;
    inline int read(){
    	int x=0,f=1;char ch=getchar();
    	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=getchar())  x=(x<<3)+(x<<1)+ch-'0';
    	return x*f;
    }
    const int N=1e2;
    int path[N+10],pre[N*N+10],now[N*N+10],child[N*N+10];
    int tot,n,m,Acnt,Bcnt,ans;
    bool use[N+10];
    void join(int x,int y){pre[++tot]=now[x],now[x]=tot,child[tot]=y;}
    bool check(int x){
    	for (int p=now[x],son=child[p];p;p=pre[p],son=child[p]){
    		if (use[son])   continue;
    		use[son]=1;
    		if (path[son]<0||check(path[son])){path[son]=x;return 1;}
    	}
    	return 0;
    }
    int main(){
    	while (1){
    		int flag=read();
    		if (!flag)  break;
    		n=read(),m=read(),tot=ans=0;
    		memset(now,0,sizeof(now));
    		memset(path,-1,sizeof(path));
    		for (int i=1;i<=m;i++){
    			int x=read(),y=read(),z=read();
    			if (!y||!z) continue;
    			join(y,z);
    		}
    		for (int i=1;i<=m;i++){
    			memset(use,0,sizeof(use));
    			if (check(i))   ans++;
    		}
    		printf("%d
    ",ans);
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    Unity编译Android的原理解析和apk打包分析
    TokuDB性能测试报告
    一起脱去小程序的外套和内衣
    go单元测试进阶篇
    小程序发布后最全解析!
    部署在腾讯云的公益网站遭受了一次CC攻击
    基于Http原理实现Android的图片上传和表单提交
    腾讯云TCCE培训认证 精彩的第一次
    【腾讯云的1001种玩法】在腾讯云上创建您的SQL Cluster(5)
    腾讯云容器服务的滚动升级使用简介
  • 原文地址:https://www.cnblogs.com/Wolfycz/p/8424729.html
Copyright © 2011-2022 走看看