Machine Schedule
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 9461 Accepted Submission (s): 4755
Problem Descriptionas We all know, machine scheduling are a very classical problem in computer science and have 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 was machines a and B. Machine A have n kinds of working modes, which is called Mode_0, Mode_1, ..., mode_n-1, Likew Ise machine B has m kinds of working modes, MODE_0, Mode_1, ..., mode_m-1. At the beginning they is both work at Mode_0.
For k jobs given, each of the them can is processed in either one of the one of the both machines in particular mode. For example, job 0 can either is processed in machine A at mode_3 or in machine B at Mode_4, Job 1 can either be processed In machine A is mode_2 or in machine B at Mode_4, and so on. Thus, for Job I, the constraint can is represent as a triple (I, X, y), which means it can be processed either 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 is 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 <) and K (K < 1000). The following k lines give the constrains of the K jobs, each of which is a triple:i, X, Y.
The input would be terminated to a line containing a single zero. Outputthe output should is one integer per line, which means the minimal times of restarting machine. Sample INPUT5 5 1 1 1 1, 2 2, 2, 2 3, 4, sample Output3 Roughly test instructions: There are two machines A and B and K need to run the task. Each machine has n,m different modes, and each task happens to run on a single machine. Machine A has mode mode_0, Mode_1, ..., mode_n-1, machine B has a pattern: Mode_0, Mode_1, ..., mode_m-1. The starting mode of work is mode_0. Each task has a corresponding operating mode, (I, X, y) represents the operating mode mode_x, mode_y on the A B machine that corresponds to the I task. the tasks on each machine can be executed in any order, but each machine will need to be restarted every time the mode is converted. Please properly arrange a machine for each task and arrange the order reasonably, so that the machine restarts as few times as possible. and ask for its value.
Ideas:
Minimum point overlay (maximum number of matches,,)
We have an edge on each task, and then we have to finish the task now and we need to restart the machine the least number of times, so that means we have to use the fewest points to connect all the edges, which translates into the smallest point covered by the naked question
Code:
#include <cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#defineN 1010using namespacestd;BOOLVis[n];intN,m,k,x,y,z,ans,girl[n],map[n][n];intRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}intFindintx) { for(intI=1; i<=m;i++) { if(!vis[i]&&Map[x][i]) {Vis[i]=true; if(girl[i]==-1|| Find (Girl[i])) {girl[i]=x;return 1;} } } return 0;}intMain () { while(1) {n=read ();if(n==0) Break; M=read (), K=read (); ans=0; memset (Map,0,sizeof(map)); memset (Girl,-1,sizeof(girl)); for(intI=1; i<=k;i++) {Z=read (), X=read (), y=read (); Map[x][y]=1; } for(intI=1; i<=n;i++) {memset (Vis,0,sizeof(VIS)); if(Find (i)) ans++; } printf ("%d\n", ans); } return 0;}
HDU--1150 Machine Schedule