HDU1150 Machine Schedule

Source: Internet
Author: User

Machine Schedule

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 3444 Accepted Submission (s): 1669


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 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 OUTPUT3

Sourceasia 2002, Beijing (Mainland China)

RECOMMENDIGNATIUS.L Test Instructions: To complete the K-task, each task can be done with a machine in a certain mode, or a B machine in a certain mode. The number of times the mode conversion was spent. The minimum number of mode conversions to dig into a task. Problem: The edge as a task, the edge of the connected point is the machine mode can complete the task, then the topic is converted to the minimum point to cover the collection of problems. Note: 1. The starting mode is 0 2.hungary the function is preceded by a call to Init, and the call is preceded by an edge of 3. The joined Edge does not consider the connection 0 state, since the first is 0 State 4. Added is the forward side. (a->b) Code:
#include <cstdio>#include<cmath>#include<cstring>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<queue>#include<map>#include<stack>using namespacestd;#defineTest Freopen ("In.txt", "R", stdin)#definePT (u,p) cout<<u<< "=" <<p<<endl;#definePB (U) push_back (u)#definePtln cout<<endl;#definePtarr (I,A,S,F) for (int i=s;i<=f;i++) {if (i!=f) cout<<a[i]<< ""; Else Cout<<a[i]<<endl;}#defineREP (I,S,F) for (int i=s;i<=f;i++)#defineRrep (I,S,F) for (int i=s;i>=f;i--)#defineCOVER (a,v) memset (A,v,sizeof (a))#defineIOS Ios_base::sync_with_stdio ()typedefLong Longll;Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;Const intmaxn= -;Const intmaxm=4000;intn,m,k,kase;structedge{intTo,next;} EDGE[MAXM];intHead[maxn],tot;voidinit () {tot=0; memset (Head,-1,sizeof(head));}voidAddedge (intUintv) {edge[tot].to=v;edge[tot].next=Head[u]; Head[u]=tot++;}intLINKER[MAXN];BOOLUSED[MAXN];BOOLDfsintu) {     for(inti=head[u];i!=-1; i=Edge[i].next) {        intv=edge[i].to; if(!Used[v]) {Used[v]=true; if(linker[v]==-1||DFS (Linker[v])) {Linker[v]=u; return true; }        }    }    return false;}intHungary () {intres=0; MEMSET (linker,-1,sizeof(linker));  for(intu=0; u<n;u++) {memset (used,false,sizeof(used)); intret=dfs (U); if(ret) res++; }    returnRes;}intMain () { while(1) {cin>>N; if(!n) Break; CIN>>m>>K;        Init ();  for(intI=0; i<k;i++)        {            intU,v1,v2; CIN>>u>>v1>>v2; if(v1>0&&v2>0) Addedge (V1,V2); } cout<Endl; }    return 0;}

Hdu1150 Machine Schedule

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.