Poj-1325-machine Schedule
Machine Schedule
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 15834 |
|
Accepted: 6776 |
Description
As we all know, machine scheduling are a very classical problem in computer science and have been studied for a very long hi Story. 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, lik Ewise 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.
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 <) 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 Input
5 5 100 1 11 1 22 1 33 1 44 2 15 2 26 2 37 2 48 3 39 4 30
Sample Output
3
Source
Beijing 2002
17957182 |
|
1325 |
Accepted |
4392K |
79MS |
g++ |
882B |
2017-12-16 21:03:57 |
Two machines, each with N and M states, can be completed by two machines for each task. So now it's just a matter of finding the smallest number of states.
You just need to find the minimum number of rotating states for machine 1. Because all the tasks can be done by machine. (use greedy, as far as possible all tasks by Machine1 completed, not completed to machine 2)
As you can see, the binary graph matches. Using the Hungarian algorithm can be solved.
(Start commit appears wrong answer, because ask is need to change the minimum number of times, the initial state is Mode_0 state, so for the task can be in the mode_0 words, can skip regardless. )
poj-1325 #include <cstdio> #include <cstring> const int MAXN = 1000 + 10; int n, m, K, MP[MAXN][MAXN], VIS[MAXN], MATCH[MAXN], LEN[MAXN]; bool Dfs (int x) {for (int i=0; i<len[x]; ++i) {int y = Mp[x][i], if (vis[y] = = 0) {Vis[y] = 1; if (Match[y] < 0 | | DFS (MAT Ch[y]) {match[y] = x; return true;}} }return false; }int Main () {freopen ("In.txt", "R", stdin); int id, x, y, ans; while (scanf ("%d", &n)! = EOF) {if (n = = 0) {break;} scanf ("%d%d", &m, &k); memset (len, 0, sizeof (len)); Memset (MP, 0, sizeof (MP)); for (int i=0; i<k; ++i) {scanf ("%d%d%d", &id, &x, &y); if (x = = 0 | | y = = 0) {continue;} mp[x] [len[x]] = y; ++LEN[X]; }memset (Match,-1, sizeof (match)); Ans = 0; for (int i=1; i<=n; ++i) {memset (Vis, 0, sizeof (VIS)); if (Dfs (i)) {++ans;}} printf ("%d\n", ans); }return 0; }
Poj-1325-machine Schedule