Machine Schedule
Time limit:1 Sec Memory limit:256 MB
Topic Connection http://acm.hdu.edu.cn/showproblem.php?pid=1150
Descriptionas we all know, machine scheduling are a very classical problem in computer science and have been studied for a V ery 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. Output
The output should is one integer per line, which means the minimal times of restarting machine.
Sample INPUT5 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
0Sample Output3HINT
Test instructions
There are 2 machines m tasks, each task on a machine needs a State x, in which the B-machine needs the state Y, then each machine starting state is 0, changing the state to spend 1, then asking you to spend the minimum cost to complete these tasks
Exercises
Consider each task as an edge, connect the x state with Y, and then find the smallest point to cover all the edges, which is a minimum point coverage problem
Code:
//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 2001#defineMoD 10007#defineEPS 1e-9//const int INF=0X7FFFFFFF; //infinitely LargeConst intinf=0x3f3f3f3f;/**///**************************************************************************************inline ll read () {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;}intMA[MAXN][MAXN];intVIS[MAXN];intMATCH[MAXN];intN,m;vector<int>E[MAXN];intDfsinta) { for(intI=0; I<e[a].size (); i++) { if(vis[e[a][i]]==0) {Vis[e[a][i]]=1; if(match[e[a][i]]==-1||DFS (Match[e[a][i])) {Match[e[a][i]]=A; return 1; } } } return 0;}intMain () { while(SCANF ("%d", &n)! =EOF) { if(n==0) Break; memset (Match,-1,sizeof(match)); for(intI=0; i<n;i++) e[i].clear (); M=read (); intk=read (); for(intI=0; i<k;i++) { intA=read (); intX=read (), y=read (); if(x>0&&y>0) {e[x].push_back (y); } } intans=0; for(intI=1; i<n;i++) {memset (Vis,0,sizeof(VIS)); if(Dfs (i) = =1) ans++; } printf ("%d\n", ans); }}
HDU 1150 Machine Schedule minimum point overlay