C-machine Schedule
Time Limit:1000MS
Memory Limit:10000KB
64bit IO Format:%I64D &%i64u Submit Status
Description as we all know, machine scheduling are a very classical problem in computer science and has been for a Very long history. Scheduling problems differ widely in the "constraints" that must is satisfied and the type of schedule . 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, lik Ewise 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 is processed in either one of the two machines in particular mode. For example, job 0 can either to 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. Thus, for Job I, the constraint can is 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 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.
Input the input file for this program consists of several configurations. The "a" one configuration contains three positive integers:n, M (N, m < K) and (K < 1000). The following k lines give the constrains of the K jobs, each line is a triple:i, X, Y.
The input is terminated by a line containing a single zero.
Output the output should be one integer/line, which means the minimal times of restarting machine.
Sample Input
5 5
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
Sample Output
3
Accode:
#pragma warning (disable:4786)//mission name is not limited in length #pragma comment (linker, "/stack:102400000,102400000")/hand-open stack #include < map> #include <set> #include <queue> #include <cmath> #include <stack> #include <cctype > #include <cstdio> #include <cstring> #include <stdlib.h> #include <iostream> #include < algorithm> #define RD (x) scanf ("%d", &x) #define RD2 (x,y) scanf ("%d%d", &x,&y) #define RD3 (x,y,z) scanf ("% d%d%d ", &x,&y,&z) #define RDS (x) scanf ("%s ", x) #define RDC (x) scanf ("%c ", &x) #define LL Long int #defi NE maxn 1005 #define MOD 1000000007 #define INF 0x3f3f3f3f//int maximum #define for (i,f_start,f_end) for (int i=f_start;i<=
F_end;++i) #define MT (x,i) memset (x,i,sizeof (x)) #define PI ACOs ( -1.0) #define E exp (1) using namespace Std;
int BMAP[MAXN][MAXN];
BOOL BMASK[MAXN];
int nx,ny,m;
int PRE[MAXN];
int findpath (int u) {for (I,1,ny) if (Bmap[u][i]&&!bmask[i]) {bmask[i]=1; if (pre[i]==-1| |
Findpath (Pre[i])) {pre[i]=u;
return 1;
} return 0;
int Maxmatch () {int res (0);
for (I,1,NX) {MT (bmask,0);
Res+=findpath (i);
return res;
} void Init () {MT (bmap,0);
MT (bmask,0);
MT (pre,-1);
int main () {while (RD (NX) &&nx) {Rd2 (ny,m);
int X,y,k;init ();
for (i,1,m) {Rd3 (k,x,y);
if (x+y) bmap[x][y]=1;
printf ("%d\n", Maxmatch ());
return 0;
}/* 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/*