-
Notifications
You must be signed in to change notification settings - Fork 0
/
yello_bricks.cpp
79 lines (59 loc) · 1.14 KB
/
yello_bricks.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
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
struct dimension {
int l;
int b;
int h;
};
long long int no_of_cubes( vector<dimension> Q, int min );
int main()
{
int s;
vector<long long int> sol;
cin >> s;
while ( s ) {
vector<dimension> Q;
int min = INT_MAX;
for ( int i = 0; i < s; i++ ) {
dimension tmp;
cin >> tmp.l;
if ( tmp.l < min )
min = tmp.l;
cin >> tmp.b;
if ( tmp.b < min )
min = tmp.b;
cin >> tmp.h;
if ( tmp.h < min )
min = tmp.h;
Q.push_back(tmp);
}
sol.push_back( no_of_cubes(Q, min) );
cin >> s;
}
for ( int i = 0; i < sol.size(); i++ ) {
cout << sol[i] << endl;
}
return 0;
}
long long int no_of_cubes( vector<dimension> Q, int min ) {
long long int sol = 0;
for ( int i = min; i >= 1; i-- ) {
int check = 1;
for ( int j = 0; j < Q.size(); j++ ) {
long long int c;
if ( Q[j].l % i == 0 && Q[j].b % i == 0 && Q[j].h % i == 0 ) {
c = ( Q[j].l / i) * ( Q[j].b/ i) * ( Q[j].h/ i );
sol = sol + c;
} else {
sol = 0;
check = 0;
break;
}
}
if ( check == 1 ) {
return sol;
}
}
}