-
Notifications
You must be signed in to change notification settings - Fork 2
/
assembly.cpp
82 lines (66 loc) · 1.41 KB
/
assembly.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/******************************************
*
* Assembly line scheduling problem
*
* Harsimran Singh
*
* Finds the order of assembly lines for
* best output
******************************************/
#include<iostream>
#define NUM 4
using namespace std;
int main()
{
int a1[NUM], a2[NUM];
int f1[NUM], f2[NUM];
int t[2][NUM] = {};
int taken[NUM];
int e1, e2, x1, x2;
for(int i = 0; i < NUM; i++)
{
cin>>a1[i];
cin>>a2[i];
}
for (int i = 0; i < NUM-1; i++)
{
cin>>t[0][i];
cin>>t[1][i];
}
e1 = 4; e2 = 5; x1 = 6; x2 = 7;
f1[0] = e1 + a1[0];
f2[0] = e2 + a2[0];
if (f1[0] < f2[0])
taken[0] = 1;
else
taken[0] = 2;
for (int i = 1 ; i < NUM; i++)
{
if(f1[i-1] + a1[i] < f2[i-1] + t[1][i-1] + a1[i])
{
f1[i] = f1[i-1] + a1[i];
}
else
f1[i] = f2[i-1] + t[1][i-1] + a1[i];
if (f2[i-1] + a2[i] < f1[i-1] + t[0][i-1] + a2[i])
f2[i] = f2[i-1] + a2[i];
else
f2[i] = f1[i-1] + t[0][i-1] + a2[i];
if (f1[i] < f2[i])
taken[i] = 1;
else
taken[i] = 2;
}
if (f1[NUM - 1] + x1 < f2[NUM - 1] + x2)
cout<<"Ans : "<<f1[NUM - 1] + x1;
else
cout<<"Ans : "<<f2[NUM - 1] + x2;
cout<<"Begin --> ";
for (int i = 0 ; i < NUM; i++)
{
cout<<taken[i]<<endl;
}
cout<<" End"<<endl;
return 0;
}