[USACO4.2.3]Job Processing

来源:互联网 发布:如何投诉淘宝平台 编辑:程序博客网 时间:2024/05/09 01:50


Job Processing

IOI'96

A factory is running a production line that requires two operations to be performed on each job: first operation "A" then operation "B". Only a certain number of machines are capable of performing each operation.

Figure 1 shows the organization of the production line that works as follows. A type "A" machine takes a job from the input container, performs operation "A" and puts the job into the intermediate container. A type "B" machine takes a job from the intermediate container, performs operation "B" and puts the job into the output container. All machines can work in parallel and independently of each other, and the size of each container is unlimited. The machines have different performance characteristics, a given machine requires a given processing time for its operation.

Give the earliest time operation "A" can be completed for all N jobs provided that the jobs are available at time 0. Compute the minimal amount of time that is necessary to perform both operations (successively, of course) on all N jobs.

PROGRAM NAME: job

INPUT FORMAT

Line 1:Three space-separated integers:
  • N, the number of jobs (1<=N<=1000).
  • M1, the number of type "A" machines (1<=M1<=30)
  • M2, the number of type "B" machines (1<=M2<=30)
Line 2..etc:M1 integers that are the job processing times of each type "A" machine (1..20) followed by M2 integers, the job processing times of each type "B" machine (1..20).

SAMPLE INPUT (file job.in)

5 2 31 1 3 1 4

OUTPUT FORMAT

A single line containing two integers: the minimum time to perform all "A" tasks and the minimum time to perform all "B" tasks (which require "A" tasks, of course).

SAMPLE OUTPUT (file job.out)

3 5



第一问: 

考虑到每一个工件都是独立的
然后我想到了NOIP普及组一道,好像是water??
不管
贪心!
就是每次加最少的地方去加
然后就解决了。


第二问:


不会。
还是贪心。
注意:(每一个工件都是独立的) 
考虑对于A处理n个工件,每一个工件都有一定的处理完A的时间
最短的处理完B的时间
类似这样:(可能机器比较少) 
1:——— 
2:————— 
3:—————— 


_1:— 
_2:——— 
_3:———— 
显然,最大和最小的匹配比较好。

题解真妙,好好理解! 



/*ID:cqz15311LANG:C++PROG:job*/#include<bits/stdc++.h>const int inf = 1 << 20;using namespace std;int a[1005],b[1005];int timea[1005],timeb[1005],time1[1005],time2[1005];int n,na,nb,Min,ans,k;int main(){freopen("job.in","r",stdin);freopen("job.out","w",stdout);scanf("%d",&n);scanf("%d%d",&na,&nb);for (int i=1;i<=na;i++) scanf("%d",&a[i]);for (int i=1;i<=nb;i++) scanf("%d",&b[i]);memset(timea,0,sizeof(timea));memset(timeb,0,sizeof(timeb));for (int i=1;i<=n;i++) {Min = inf;for (int j=1;j<=na;j++){if (timea[j] + a[j] < Min) {Min = timea[j] + a[j];k = j;}}timea[k] = time1[i] = Min;}printf("%d ",Min);for (int i=1;i<=n;i++){Min = inf;for (int j=1;j<=nb;j++){if (timeb[j] + b[j] < Min){Min = timeb[j] + b[j];k = j;}}timeb[k] = time2[i] = Min;}ans = 0;for (int i=1;i<=n;i++)ans = max(ans,time1[i] + time2[n-i+1]);printf("%d\n",ans);fclose(stdin);fclose(stdout);}/*Executing...   Test 1: TEST OK [0.000 secs, 4196 KB]   Test 2: TEST OK [0.000 secs, 4196 KB]   Test 3: TEST OK [0.000 secs, 4196 KB]   Test 4: TEST OK [0.000 secs, 4196 KB]   Test 5: TEST OK [0.000 secs, 4196 KB]   Test 6: TEST OK [0.000 secs, 4196 KB]   Test 7: TEST OK [0.000 secs, 4196 KB]   Test 8: TEST OK [0.000 secs, 4196 KB]   Test 9: TEST OK [0.000 secs, 4196 KB]   Test 10: TEST OK [0.000 secs, 4196 KB]   Test 11: TEST OK [0.000 secs, 4196 KB]   Test 12: TEST OK [0.000 secs, 4196 KB]All tests OK.*/


原创粉丝点击